Skip to content

Commit ceab492

Browse files
sirus20x6pd3
authored andcommitted
Fix two bugs in tabix.c: dead code and missing NULL check
1. Move `detect = 0` outside the error else-block where it was unreachable dead code after `return 1`. It now executes when a valid -p type is matched, properly suppressing auto-detection. 2. Add a NULL check on the bgzf_open() return value in the is_all branch to avoid dereferencing a NULL pointer when the file cannot be opened.
1 parent 1860cb6 commit ceab492

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tabix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ int main_tabix(int argc, char *argv[])
5353
else {
5454
fprintf(stderr, "The type '%s' not recognised\n", optarg);
5555
return 1;
56-
detect = 0;
5756
}
57+
detect = 0;
5858

5959
}
6060
if (optind == argc) {
@@ -77,6 +77,10 @@ int main_tabix(int argc, char *argv[])
7777
BGZF *fp;
7878
s.l = s.m = 0; s.s = 0;
7979
fp = bgzf_open(argv[optind], "r");
80+
if (!fp) {
81+
fprintf(stderr, "[E::%s] could not open '%s'\n", __func__, argv[optind]);
82+
return 1;
83+
}
8084
while (bgzf_getline(fp, '\n', &s) >= 0) puts(s.s);
8185
bgzf_close(fp);
8286
free(s.s);

0 commit comments

Comments
 (0)