From 79e72f58b564d6a3fcb753b80614505a00ac0ff1 Mon Sep 17 00:00:00 2001 From: Jacob Morrison Date: Mon, 26 Feb 2024 09:33:41 -0500 Subject: [PATCH] Fix Issue #49 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. --- src/epiread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/epiread.c b/src/epiread.c index 3a354ae..2ce1517 100644 --- a/src/epiread.c +++ b/src/epiread.c @@ -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