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 8, 2024
1 parent 61b037b commit 2d01aca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion faidx.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static int fai_build3_core(const char *fn, const char *fnfai, const char *fngzi)
bgzf = bgzf_open(fn, "r");

if ( !bgzf ) {
hts_log_error("Failed to open the file %s", fn);
hts_log_error("Failed to open the file %s : %s", fn, strerror(errno));
goto fail;
}

Expand Down
19 changes: 16 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,18 @@ 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) {
if (hts_opt_apply(fp, fmt->specific) != 0) {
if (((hts_opt*)fmt->specific)->opt == CRAM_OPT_REFERENCE &&
(errno == ENOENT || errno == EIO || errno == EBADF ||
errno == EACCES || errno == EISDIR)) {
/* error during reference file operation
for these specific errors, set the error as EINVAL */
errno = EINVAL;
}
goto error;

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

Expand Down Expand Up @@ -1595,6 +1604,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 2d01aca

Please sign in to comment.