Skip to content

Commit

Permalink
Remove unneeded abort check in cram encoding.
Browse files Browse the repository at this point in the history
Also fixed a potential illegal memory access caused by the return
value of cram_encode_aux, and added more belt and braces memory free
requests for the new embed_ref=2 option.
  • Loading branch information
jkbonfield committed Jun 1, 2022
1 parent 7039fc9 commit 9da79aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cram/cram_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,6 @@ int cram_encode_container(cram_fd *fd, cram_container *c) {
// based on MD:Z tags.
if ((c->ref_id = bam_ref(b)) >= 0) {
c->ref_free = 1;
if (c->ref) abort();
c->ref = NULL;
}
}
Expand Down Expand Up @@ -2626,7 +2625,9 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c,
free(orig);

if (err) *err = 0;
return rg;

// rg from within bam_aux, not rg from our aux copy.
return rg ? (char *)bam_aux(b) + (rg - orig) : NULL;

err:
block_err:
Expand Down Expand Up @@ -2841,6 +2842,7 @@ static int cram_extend_ref(cram_container *c, bam1_t *b) {

memset(c->ref + old_end - c->ref_start, 'N', c->ref_end - old_end);
memset(c->ref_set + old_end - c->ref_start, 0, c->ref_end - old_end);
c->ref_free = 1;
}

return 0;
Expand Down

0 comments on commit 9da79aa

Please sign in to comment.