Skip to content

Commit

Permalink
Fix Issue #49
Browse files Browse the repository at this point in the history
gzgetc returns -1 for both an error and EOF. If the file is empty, it
will appear on the first character, so add an check that the the -1 is
being found on the first character instead of at any point.
  • Loading branch information
jamorrison committed Feb 26, 2024
1 parent 542c34d commit 79e72f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/epiread.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,14 @@ episnp_chrom1_v *bed_init_episnp(char *snp_bed_fn) {
wzfatal("Could not find SNP BED: %s\n", snp_bed_fn);
}

uint8_t first_char = 1;
while (1) {
int c = gzgetc(fh);
if (c < 0) {
if (c < 0 && first_char) {
free(line.s);
wzfatal("SNP BED (%s) is empty\n", snp_bed_fn);
}
first_char = 0;
if (c=='\n' || c==EOF) {
if (strcount_char(line.s, '\t')==8) {
// Get chromosome
Expand Down

0 comments on commit 79e72f5

Please sign in to comment.