Skip to content

Fix the data pointer of hts_itr_next.#1180

Merged
daviesrob merged 1 commit intosamtools:developfrom
valeriuo:fix_bam_itr
Nov 20, 2020
Merged

Fix the data pointer of hts_itr_next.#1180
daviesrob merged 1 commit intosamtools:developfrom
valeriuo:fix_bam_itr

Conversation

@valeriuo
Copy link
Copy Markdown
Contributor

bam_itr_next now sets the data argument of hts_itr_next to the BAM file pointer (of htsFile * type).

Fixes #1179

@jmarshall
Copy link
Copy Markdown
Member

Historically this code was like this because for BAM files hts_itr_next() used its BGZF *fp argument (and ignored its void *data argument) and called bam_readrec() which used bam_read1() with the BGZF *fp argument. Meanwhile for CRAM files hts_itr_next() used the void *data argument but ignored the BGZF *fp argument.

This changed — and this bug was introduced — when iterating over SAM files was added and bam_readrec() (using bam_read1() and BGZF *fp) was replaced by sam_readrec() (using sam_read1() and void *data aka htsFile *).

Since then for BAM files, hts_itr_next() has mixed up seeking on the BGZF * with reading from the htsFile *. This works more by luck than design!

So IMHO this bug report is an indication that this code needs a careful review and, if moving to htsFile * everywhere in hts_itr_next(), streamlining and removal of the legacy BGZF * parameter (ABI issues notwithstanding). And/or more heavily deprecating the legacy bam_itr_* functions.

@daviesrob daviesrob merged commit 51275bc into samtools:develop Nov 20, 2020
@daviesrob
Copy link
Copy Markdown
Member

Well, the bam_itr_* interface has now effectively gone as it just calls the sam_itr_* equivalents. You're right, though, the iterator code is quite hairy and would benefit from some simplification.

@valeriuo valeriuo deleted the fix_bam_itr branch January 7, 2021 16:49
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.

NULL pointer on using bam_itr_next

3 participants