Skip to content

Commit 5b0bb75

Browse files
committed
Added checks to return value of hts_opt_apply.
Also made cram_set_voption set errno using a couple appropriate POSIX error codes, to avoid confusing "Success" error messages. Fixes #452
1 parent 6d2810c commit 5b0bb75

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

cram/cram_io.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4399,8 +4399,10 @@ int cram_set_option(cram_fd *fd, enum hts_fmt_option opt, ...) {
43994399
int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
44004400
refs_t *refs;
44014401

4402-
if (!fd)
4402+
if (!fd) {
4403+
errno = EBADF;
44034404
return -1;
4405+
}
44044406

44054407
switch (opt) {
44064408
case CRAM_OPT_DECODE_MD:
@@ -4480,6 +4482,7 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
44804482
(major == 3 && minor == 0))) {
44814483
fprintf(stderr, "Unknown version string; "
44824484
"use 1.0, 2.0, 2.1 or 3.0\n");
4485+
errno = EINVAL;
44834486
return -1;
44844487
}
44854488
fd->version = major*256 + minor;
@@ -4535,6 +4538,7 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
45354538

45364539
default:
45374540
fprintf(stderr, "Unknown CRAM option code %d\n", opt);
4541+
errno = EINVAL;
45384542
return -1;
45394543
}
45404544

hts.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt)
400400
if (fp == NULL) goto error;
401401

402402
if (fmt && fmt->specific)
403-
hts_opt_apply(fp, fmt->specific);
403+
if (hts_opt_apply(fp, fmt->specific) != 0)
404+
goto error;
405+
404406

405407
return fp;
406408

@@ -663,7 +665,11 @@ static int hts_process_opts(htsFile *fp, const char *opts) {
663665
if (hts_parse_opt_list(&fmt, opts) != 0)
664666
return -1;
665667

666-
hts_opt_apply(fp, fmt.specific);
668+
if (hts_opt_apply(fp, fmt.specific) != 0) {
669+
hts_opt_free(fmt.specific);
670+
return -1;
671+
}
672+
667673
hts_opt_free(fmt.specific);
668674

669675
return 0;

0 commit comments

Comments
 (0)