From 27b872f20395289f7a491c763dff92aed9fc3bb0 Mon Sep 17 00:00:00 2001 From: Valeriu Ohan Date: Tue, 28 Apr 2020 12:58:32 +0100 Subject: [PATCH] Address code review comments. --- sam.c | 6 ++++-- vcf.c | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sam.c b/sam.c index 878fcc270..dc8b9c183 100644 --- a/sam.c +++ b/sam.c @@ -3220,8 +3220,10 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) // reference count the structure. int sam_write1(htsFile *fp, const sam_hdr_t *hdr, const bam1_t *b) { - const sam_hdr_t *h = hdr; - if (!h) h = fp->bam_header; + if (!fp || !b) { errno = EINVAL; return -1; } + const sam_hdr_t *h = hdr ? hdr : fp->bam_header; + if (!h) { hts_log_error("No header available for file \"%s\"", fp->fn); return -1; } + switch (fp->format.format) { case binary_format: fp->format.category = sequence_data; diff --git a/vcf.c b/vcf.c index 8416c5e80..c302cba0b 100644 --- a/vcf.c +++ b/vcf.c @@ -3291,8 +3291,6 @@ static int vcf_idx_init(htsFile *fp, bcf_hdr_t *h, int min_shift, const char *fn u32_to_le(0, conf+20); // n.skip u32_to_le(0, conf+24); // ref name len if (hts_idx_set_meta(fp->idx, sizeof(conf)*sizeof(*conf), (uint8_t *)conf, 1) < 0) { - hts_idx_destroy(fp->idx); - fp->idx = NULL; return -1; } fp->fnidx = strdup(fnidx);