Skip to content

Commit

Permalink
fix for incorrect failure message with invalid reference file and nul…
Browse files Browse the repository at this point in the history
…l check
  • Loading branch information
vasudeva8 committed Jan 3, 2024
1 parent 61b037b commit 63837b5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions hts.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt)
fn = rmme;
}

errno = 0; //reset to ensure appropriate error display
hfile = hopen(fn, smode);
if (hfile == NULL) goto error;

Expand All @@ -938,10 +939,19 @@ htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt)
fmt->format == fastq_format))
fp->format.format = fmt->format;

if (fmt && fmt->specific)
if (hts_opt_apply(fp, fmt->specific) != 0)
if (fmt && fmt->specific) {
int save_errno = errno;
if (hts_opt_apply(fp, fmt->specific) != 0) {
if (((hts_opt*)fmt->specific)->opt == CRAM_OPT_REFERENCE) {
const char *ref = ((hts_opt*)fmt->specific)->val.s;
hts_log_error("Couldn't load reference \"%s\" : %s",
ref ? ref : "(NULL)", strerror(errno));
// set error to error prior to reference file operation
errno = save_errno;
}
goto error;

}
}
if ( rmme ) free(rmme);
return fp;

Expand Down Expand Up @@ -1595,6 +1605,10 @@ htsFile *hts_hopen(hFILE *hfile, const char *fn, const char *mode)
int hts_close(htsFile *fp)
{
int ret = 0, save;
if (!fp) {
errno = EINVAL;
return -1;
}

switch (fp->format.format) {
case binary_format:
Expand Down

0 comments on commit 63837b5

Please sign in to comment.