Skip to content

Commit e93f740

Browse files
jmarshallwhitwham
authored andcommitted
Do not return -1 (which signals EOF) in error cases
Return an error (-2) rather than EOF (-1) on seek failure in hts_itr_multi_next() and hence sam_itr_next(). Similarly return error indications (-2) on seek and header failure for SAM input in sam_read1(), on bam_set1() failure for FASTQ input in sam_read1(), and on memory allocation failure in vcf_parse() and hence bcf_read(). (All of these functions are documented as returning -1 on EOF and <= -2 on error.)
1 parent 87d406c commit e93f740

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Diff for: hts.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -4291,7 +4291,7 @@ int hts_itr_multi_next(htsFile *fd, hts_itr_t *iter, void *r)
42914291
if (iter->curr_off) { // seek to the start
42924292
if (iter->seek(fp, iter->curr_off, SEEK_SET) < 0) {
42934293
hts_log_error("Seek at offset %" PRIu64 " failed.", iter->curr_off);
4294-
return -1;
4294+
return -2;
42954295
}
42964296
iter->curr_off = 0; // only seek once
42974297
}
@@ -4369,7 +4369,7 @@ int hts_itr_multi_next(htsFile *fd, hts_itr_t *iter, void *r)
43694369
next_range = 0;
43704370
if (iter->seek(fp, iter->nocoor_off, SEEK_SET) < 0) {
43714371
hts_log_error("Seek at offset %" PRIu64 " failed.", iter->nocoor_off);
4372-
return -1;
4372+
return -2;
43734373
}
43744374
if (iter->is_cram) {
43754375
cram_range r = { HTS_IDX_NOCOOR };
@@ -4421,7 +4421,7 @@ int hts_itr_multi_next(htsFile *fd, hts_itr_t *iter, void *r)
44214421
if (iter->seek(fp, iter->curr_off, SEEK_SET) < 0) {
44224422
hts_log_error("Seek at offset %" PRIu64
44234423
" failed.", iter->curr_off);
4424-
return -1;
4424+
return -2;
44254425
}
44264426

44274427
// Find the genomic range matching this interval.
@@ -4479,7 +4479,7 @@ int hts_itr_multi_next(htsFile *fd, hts_itr_t *iter, void *r)
44794479
if (iter->seek(fp, iter->curr_off, SEEK_SET) < 0) {
44804480
hts_log_error("Seek at offset %" PRIu64 " failed.",
44814481
iter->curr_off);
4482-
return -1;
4482+
return -2;
44834483
}
44844484
}
44854485
}

Diff for: sam.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -4190,6 +4190,7 @@ static int fastq_parse1(htsFile *fp, bam1_t *b) {
41904190
-1, -1, 0, // mate
41914191
x->seq.l, x->seq.s, x->qual.s,
41924192
0);
4193+
if (ret < 0) return -2;
41934194

41944195
// Identify Illumina CASAVA strings.
41954196
// <read>:<is_filtered>:<control_bits>:<barcode_sequence>
@@ -4286,7 +4287,7 @@ static inline int sam_read1_sam(htsFile *fp, sam_hdr_t *h, bam1_t *b) {
42864287
return -2;
42874288
}
42884289
if (bgzf_seek(fp->fp.bgzf, fp->fp.bgzf->seeked, SEEK_SET) < 0)
4289-
return -1;
4290+
return -2;
42904291
fp->fp.bgzf->seeked = 0;
42914292
goto err_recover;
42924293
}
@@ -4308,7 +4309,7 @@ static inline int sam_read1_sam(htsFile *fp, sam_hdr_t *h, bam1_t *b) {
43084309

43094310
if (fd->h != h) {
43104311
hts_log_error("SAM multi-threaded decoding does not support changing header");
4311-
return -1;
4312+
return -2;
43124313
}
43134314

43144315
sp_bams *gb = fd->curr_bam;

Diff for: vcf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
37653765
// parsing. Eg to do memcmp(key, "END", 4) in vcf_parse_info over
37663766
// the more straight forward looking strcmp, giving a speed advantage.
37673767
if (ks_resize(s, s->l+4) < 0)
3768-
return -1;
3768+
return -2;
37693769

37703770
// Force our memory to be initialised so we avoid the technicality of
37713771
// undefined behaviour in using a 4-byte memcmp. (The reality is this

0 commit comments

Comments
 (0)