Skip to content

Commit

Permalink
Only test for successful buffer allocation if a buffer needs to be al…
Browse files Browse the repository at this point in the history
…located

No buffer is allocated when using fractions of original reads (instead of a targeted number of reads), so the alloc always fails when using fractions.   

Not sure if you'll want check before free at the bottom... I don't think it is needed, just for clarity/future.
  • Loading branch information
bwlang committed Mar 3, 2014
1 parent 30213ae commit e8989e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions seqtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ int stk_sample(int argc, char *argv[])
frac = atof(argv[optind+1]);
if (frac > 1.) num = (uint64_t)(frac + .499), frac = 0.;
if (num > 0) buf = calloc(num, sizeof(kseq_t));
if (buf == NULL) {
if (num > 0 && buf == NULL) {
fprintf(stderr, "Could not allocate enough memory for %" PRIu64 " sequences. Exiting...\n", num);
free(kr);
exit(EXIT_FAILURE);
Expand All @@ -971,7 +971,7 @@ int stk_sample(int argc, char *argv[])
if (p->seq.l) stk_printseq(p, UINT_MAX);
free(p->seq.s); free(p->qual.s); free(p->name.s);
}
free(buf);
if (buf != NULL) free(buf);
return 0;
}

Expand Down

0 comments on commit e8989e9

Please sign in to comment.