Skip to content

Commit

Permalink
Allow for refs up to UINT32_MAX long in header
Browse files Browse the repository at this point in the history
Quick update to push the ref length as far as possible without
making the bam_hdr_t target_len array bigger.
  • Loading branch information
daviesrob committed Aug 13, 2018
1 parent 0fc857f commit 7d480cb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ bam_hdr_t *sam_hdr_parse(int l_text, const char *text)
for (p = text; *p; ++p) {
if (strncmp(p, "@SQ\t", 4) == 0) {
char *sn = 0;
int ln = -1;
int64_t ln = -1;
for (q = p + 4;; ++q) {
if (strncmp(q, "SN:", 3) == 0) {
q += 3;
Expand All @@ -927,6 +927,10 @@ bam_hdr_t *sam_hdr_parse(int l_text, const char *text)
if (sn && ln >= 0) {
khint_t k;
int absent;
if (ln > UINT32_MAX) {
hts_log_error("Reference '%s' is too long", sn);
return NULL; // FIXME: Leaks memory
}
k = kh_put(s2i, d, sn, &absent);
if (!absent) {
hts_log_warning("Duplicated sequence '%s'", sn);
Expand Down Expand Up @@ -1111,7 +1115,7 @@ int sam_hdr_write(htsFile *fp, const bam_hdr_t *h)
for (i = 0; i < h->n_targets; ++i) {
fp->line.l = 0;
kputsn("@SQ\tSN:", 7, &fp->line); kputs(h->target_name[i], &fp->line);
kputsn("\tLN:", 4, &fp->line); kputw(h->target_len[i], &fp->line); kputc('\n', &fp->line);
kputsn("\tLN:", 4, &fp->line); kputuw(h->target_len[i], &fp->line); kputc('\n', &fp->line);
if ( hwrite(fp->fp.hfile, fp->line.s, fp->line.l) != fp->line.l ) return -1;
}
}
Expand Down

0 comments on commit 7d480cb

Please sign in to comment.