Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/t/bamtools_filter.cpp: simplify GetScriptContents(). #238

Closed
wants to merge 1 commit into from

Conversation

vpa1977
Copy link
Contributor

@vpa1977 vpa1977 commented Jul 9, 2024

This MR resolves #237

Changes:

  • Make 'feof(inFile)' a while condition (to avoid infinite loop in the code)
  • break when fgets() returns NULL (no data to read)
  • check ferror() - fgets() return value is undefined behaviour in this case.

Testing:

  • Running
    bamtools filter -script filter_script -in ./tests/data/sam_spec_example.bam -out out.bam with filter_script
{
  "filters" : 
    [
      { "id" : "inAnyErrorReadGroup",
        "tag" : "RG:ERR*"
      },
      { "id" : "highMapQuality",
        "mapQuality" : ">=75"
      },
      { "id" : "bothMatesMapped",
        "isMapped" : "true",
        "isMateMapped" : "true"
      }
    ],
  "rule" : "!inAnyErrorReadGroup & (highMapQuality | bothMatesMapped)"
}

succeeds


// peek ahead, make sure there is data available
char ch = fgetc(inFile);
ungetc(ch, inFile);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man this is terrible code

@SoapZA SoapZA closed this in 636ee0f Jul 12, 2024
@SoapZA
Copy link
Collaborator

SoapZA commented Jul 12, 2024

@vpa1977 I've improved your commits a bit. Could you try HEAD once more before I cut a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

infinite loop in const std::string FilterTool::FilterToolPrivate::GetScriptContents() on s390x, arm, ppc64el
2 participants