Skip to content

Commit

Permalink
Fix out by one error on extend_ref memory allocation.
Browse files Browse the repository at this point in the history
Fixes samtools#1693 which read 1 byte beyond the end of the allocated c->ref
array.
  • Loading branch information
jkbonfield committed Nov 16, 2023
1 parent 8557b64 commit 5166c1f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cram/cram_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ static inline int extend_ref(char **ref, uint32_t (**hist)[5], hts_pos_t pos,
hts_pos_t old_end = *ref_end ? *ref_end : ref_start;
hts_pos_t new_end = *ref_end = ref_start + 1000 + (pos-ref_start)*1.5;

char *tmp = realloc(*ref, *ref_end-ref_start);
char *tmp = realloc(*ref, *ref_end-ref_start+1);
if (!tmp)
return -1;
*ref = tmp;
Expand Down

0 comments on commit 5166c1f

Please sign in to comment.