Skip to content

Commit

Permalink
Fixed a dumb typo in the line reallocation for threaded SAM decoding.
Browse files Browse the repository at this point in the history
(The +NM/2 on the wrong side of the comparison!)

The +8 changes here may not be necessary, but we did it for some
allocs so I'm just being consistent and making sure it's always got 8
more than it uses.  Either it's not necessary in which case those
changes are harmless, or it is necessary in which case we were
sometimes not always leaving at least 8 bytes remaining.

I believe this fixes samtools/samtools#1293
  • Loading branch information
jkbonfield committed Aug 5, 2020
1 parent b2f0e07 commit cccd680
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,8 @@ static void *sam_dispatcher_read(void *vp) {
l = calloc(1, sizeof(*l));
if (!l)
goto err;
l->alloc = NM+8; // +8 for optimisation in sam_parse1
l->data = malloc(l->alloc);
l->alloc = NM;
l->data = malloc(l->alloc+8); // +8 for optimisation in sam_parse1
if (!l->data) {
free(l);
l = NULL;
Expand All @@ -2579,8 +2579,8 @@ static void *sam_dispatcher_read(void *vp) {
}
l->next = NULL;

if (l->alloc+NM/2 < line_frag) {
char *rp = realloc(l->data, line_frag+NM/2);
if (l->alloc < line_frag+NM/2) {
char *rp = realloc(l->data, line_frag+NM/2 +8);
if (!rp)
goto err;
l->alloc = line_frag+NM/2;
Expand Down Expand Up @@ -2613,7 +2613,7 @@ static void *sam_dispatcher_read(void *vp) {
// entire buffer is part of a single line
if (cp == l->data) {
line_frag = l->data_size;
char *rp = realloc(l->data, l->alloc * 2);
char *rp = realloc(l->data, l->alloc * 2 + 8);
if (!rp)
goto err;
l->alloc *= 2;
Expand Down

0 comments on commit cccd680

Please sign in to comment.