Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch errors from bgzf_getline() in hts_readlist, hts_readlines #1554

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions hts.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* hts.c -- format-neutral I/O, indexing, and iterator API functions.

Copyright (C) 2008, 2009, 2012-2022 Genome Research Ltd.
Copyright (C) 2008, 2009, 2012-2023 Genome Research Ltd.
Copyright (C) 2012, 2013 Broad Institute.

Author: Heng Li <[email protected]>
Expand Down Expand Up @@ -1934,8 +1934,9 @@ char **hts_readlist(const char *string, int is_file, int *_n)
if ( !fp ) return NULL;

kstring_t str;
int ret;
str.s = 0; str.l = str.m = 0;
while (bgzf_getline(fp, '\n', &str) >= 0)
while ((ret = bgzf_getline(fp, '\n', &str)) >= 0)
{
if (str.l == 0) continue;
if (hts_resize(char*, n + 1, &m, &s, 0) < 0)
Expand All @@ -1945,6 +1946,8 @@ char **hts_readlist(const char *string, int is_file, int *_n)
goto err;
n++;
}
if (ret < -1) // Read error
goto err;
bgzf_close(fp);
free(str.s);
}
Expand Down Expand Up @@ -1991,8 +1994,9 @@ char **hts_readlines(const char *fn, int *_n)
BGZF *fp = bgzf_open(fn, "r");
if ( fp ) { // read from file
kstring_t str;
int ret;
str.s = 0; str.l = str.m = 0;
while (bgzf_getline(fp, '\n', &str) >= 0) {
while ((ret = bgzf_getline(fp, '\n', &str)) >= 0) {
if (str.l == 0) continue;
if (hts_resize(char *, n + 1, &m, &s, 0) < 0)
goto err;
Expand All @@ -2001,6 +2005,8 @@ char **hts_readlines(const char *fn, int *_n)
goto err;
n++;
}
if (ret < -1) // Read error
goto err;
bgzf_close(fp);
free(str.s);
} else if (*fn == ':') { // read from string
Expand Down