diff --git a/src/grib_util.c b/src/grib_util.c index c5f32a502..de8ba1056 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -1851,12 +1851,15 @@ int is_index_file(const char* filename) char buf[8]={0,}; const char* str="GRBIDX"; int ret=0; + size_t size = 0; fh=fopen(filename,"r"); if (!fh) return 0; - fread(buf,1,1,fh); - fread(buf,6,1,fh); + size=fread(buf,1,1,fh); + if (size != 1) return 0; + size=fread(buf,6,1,fh); + if (size != 1) return 0; ret=!strcmp(buf,str); diff --git a/tests/index.sh b/tests/index.sh index cb714669d..4e80bce69 100755 --- a/tests/index.sh +++ b/tests/index.sh @@ -13,12 +13,6 @@ . ./include.sh infile=${data_dir}/index.grib -#if [ ! -f ${infile} ] -#then -# echo no data to test -# exit 0 -#fi - $EXEC ${test_dir}/index ${infile} > index.out diff index.out ${data_dir}/index.ok @@ -32,9 +26,30 @@ rm -f index.out out.gribidx #------------------------------- # Test grib_index_build #------------------------------- -tempIndex=temp.$$.ix +tempIndex=temp.$$.idx +tempOut=temp.$$.out +tempRef=temp.$$.ref ${tools_dir}/grib_index_build -o $tempIndex ${infile} >/dev/null -${tools_dir}/grib_dump -D ${tempIndex} > /dev/null + +# Must remove first two lines and the last (filename specifics) +${tools_dir}/grib_dump -D ${tempIndex} | sed '1,2d' | sed '$d' > $tempOut +cat $tempOut + +cat > $tempRef <