From afb35a355cc28926c1588ab8a643c0e65941f579 Mon Sep 17 00:00:00 2001 From: fgvieira <1151762+fgvieira@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:25:07 +0200 Subject: [PATCH] Improve error message on EOF --- shared/read_data.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shared/read_data.cpp b/shared/read_data.cpp index ca2e123..b479fb3 100644 --- a/shared/read_data.cpp +++ b/shared/read_data.cpp @@ -28,8 +28,12 @@ double*** read_geno(char *in_geno, bool in_bin, bool in_probs, bool *in_logscale for(uint64_t s = 0; s < n_sites; s++){ if(in_bin){ for(uint64_t i = 0; i < n_ind; i++){ - if( gzread(in_geno_fh, geno[i][s], N_GENO * sizeof(double)) != N_GENO * sizeof(double) ) - error(__FUNCTION__, "cannot read binary GENO file. Check GENO file and number of sites!"); + if( gzread(in_geno_fh, geno[i][s], N_GENO * sizeof(double)) != N_GENO * sizeof(double) ){ + if (gzeof(in_geno_fh)) + error(__FUNCTION__, "GENO file at premature EOF. Check GENO file and number of sites!"); + else + error(__FUNCTION__, "cannot read binary GENO file. Check GENO file and number of sites!"); + } if(!*in_logscale) conv_space(geno[i][s], N_GENO, log); // Normalize GL @@ -42,8 +46,12 @@ double*** read_geno(char *in_geno, bool in_bin, bool in_probs, bool *in_logscale } } else{ - if( gzgets(in_geno_fh, buf, BUFF_LEN) == NULL) - error(__FUNCTION__, "cannot read GZip GENO file. Check GENO file and number of sites!"); + if( gzgets(in_geno_fh, buf, BUFF_LEN) == NULL){ + if (gzeof(in_geno_fh)) + error(__FUNCTION__, "GENO file at premature EOF. Check GENO file and number of sites!"); + else + error(__FUNCTION__, "cannot read GZip GENO file. Check GENO file and number of sites!"); + } // Remove trailing newline chomp(buf); // Check if empty