Skip to content

Commit

Permalink
Fix a containment bug in cram_index_last.
Browse files Browse the repository at this point in the history
The index is a loaded into a nested containment list, so the last
entry in the index array is not necessarily the last slice, as the
last slice may be entirely contained within a previous one.

Fixes #1639
  • Loading branch information
jkbonfield committed Jul 6, 2023
1 parent e86126b commit f4a3b99
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cram/cram_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ cram_index *cram_index_last(cram_fd *fd, int refid, cram_index *from) {

slice = fd->index[refid+1].nslice - 1;

return &from->e[slice];
// e is the last entry in the nested containment list, but it may
// contain further slices within it.
cram_index *e = &from->e[slice];
while (e->e_next)
e = e->e_next;

return e;
}

/*
Expand Down

0 comments on commit f4a3b99

Please sign in to comment.