Skip to content

fix: add null check to tidname on HeaderView#515

Open
minorllama wants to merge 3 commits into
rust-bio:masterfrom
minorllama:master
Open

fix: add null check to tidname on HeaderView#515
minorllama wants to merge 3 commits into
rust-bio:masterfrom
minorllama:master

Conversation

@minorllama

Copy link
Copy Markdown

This fixes: #505 by adding a null check to tid2name. also, added a test for the segfaulting example. Returning empty CStr on missing tid (when the C ffi return NULL) should also be documented.

@minorllama minorllama changed the title add null check to tidname on HeaderView fix:add null check to tidname on HeaderView Jul 13, 2026
@minorllama minorllama changed the title fix:add null check to tidname on HeaderView fix: add null check to tidname on HeaderView Jul 13, 2026

@dlejeune dlejeune left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @minorllama thanks so much for this PR. Two things:

  1. Can you remove the commented out code please

  2. More a thought, but would it be worth changing the return type of tid2name to be an Option<&[u8]> instead of returning an empty string? Not necessarily something to change now since that breaks the API, but maybe something to consider.

@minorllama

Copy link
Copy Markdown
Author

@dlejeune Removed commented out old code with this commit .

Yes, I agree it really should return an option as the getting back an empty string can be ambiguous, but it will break the api and will involve some refactoring.

To log, this is where I see NULL being returned from the htslib.

@dlejeune

Copy link
Copy Markdown

Thanks @minorllama. Can you correct the errors raised by the Formatting and Linting workflows? You just need to run cargo fmt and RUSTFLAGS="-Dwarnings" cargo clippy --all-features --all-targets -- -Dclippy::all -Dunused_imports and then fix the issues that come up there. That should appease the CI workflow

@minorllama

Copy link
Copy Markdown
Author

@dlejeune

$ cargo fmt ; RUSTFLAGS="-Dwarnings" cargo clippy --all-features --all-targets -- -Dclippy::all -Dunused_imports ; git add -u -v
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
add 'src/bam/mod.rs'

and pushed.

I was looking for a contrib.md in the root project for specs as these, but could not find them. Is there a contributing document that can be linked/added?

@dlejeune

Copy link
Copy Markdown

Thanks @minorllama. I see it's still failing on the linting but it's not related to your code so I'm happy with this this PR.

Yeah, there's no contrib.md. It's on my TODO list to write one at some point, but if you want to submit one then please do.

@johanneskoester I'm happy for this PR to be merged since the linting errors aren't related to the code changes.

@coveralls

coveralls commented Jul 16, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29440250837

Coverage increased (+0.05%) to 82.129%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (3 of 4 lines covered, 75.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/bam/mod.rs 4 3 75.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3391
Covered Lines: 2785
Line Coverage: 82.13%
Coverage Strength: 27266.68 hits per line

💛 - Coveralls

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.

Segfault when using an invalid TID for a BAM HeaderView

3 participants