Skip to content

Commit a4fab45

Browse files
committed
Address code review comments.
1 parent 445de25 commit a4fab45

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

sam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,8 +3220,10 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
32203220
// reference count the structure.
32213221
int sam_write1(htsFile *fp, const sam_hdr_t *hdr, const bam1_t *b)
32223222
{
3223-
const sam_hdr_t *h = hdr;
3224-
if (!h) h = fp->bam_header;
3223+
if (!fp || !b) { errno = EINVAL; return -1; }
3224+
const sam_hdr_t *h = hdr ? hdr : fp->bam_header;
3225+
if (!h) { hts_log_error("No header available for file \"%s\"", fp->fn); return -1; }
3226+
32253227
switch (fp->format.format) {
32263228
case binary_format:
32273229
fp->format.category = sequence_data;

vcf.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,7 +3296,11 @@ static int vcf_idx_init(htsFile *fp, bcf_hdr_t *h, int min_shift, const char *fn
32963296
return -1;
32973297
}
32983298
fp->fnidx = strdup(fnidx);
3299-
if (!fp->fnidx) return -1;
3299+
if (!fp->fnidx) {
3300+
hts_idx_destroy(fp->idx);
3301+
fp->idx = NULL;
3302+
return -1;
3303+
}
33003304

33013305
return 0;
33023306
}
@@ -3317,7 +3321,11 @@ int bcf_idx_init(htsFile *fp, bcf_hdr_t *h, int min_shift, const char *fnidx) {
33173321
fp->idx = hts_idx_init(nids, HTS_FMT_CSI, bgzf_tell(fp->fp.bgzf), min_shift, n_lvls);
33183322
if (!fp->idx) return -1;
33193323
fp->fnidx = strdup(fnidx);
3320-
if (!fp->fnidx) return -1;
3324+
if (!fp->fnidx) {
3325+
hts_idx_destroy(fp->idx);
3326+
fp->idx = NULL;
3327+
return -1;
3328+
}
33213329

33223330
return 0;
33233331
}

0 commit comments

Comments
 (0)