summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
Diffstat (limited to 'hl')
-rw-r--r--hl/test/test_ds.c18
-rw-r--r--hl/test/test_image.c55
2 files changed, 60 insertions, 13 deletions
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index 7b6fb82..47929e6 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -4870,8 +4870,16 @@ static int read_data( const char* fname,
}
for(i=0, nelms=1; i < ndims; i++) {
- fscanf( f, "%s %u", str, &j);
- fscanf( f, "%d",&n );
+ if(fscanf( f, "%s %u", str, &j) && HDferror(f)) {
+ printf( "fscanf error in file %s\n", data_file );
+ HDfclose(f);
+ return -1;
+ } /* end if */
+ if(fscanf( f, "%d",&n ) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s\n", data_file );
+ HDfclose(f);
+ return -1;
+ } /* end if */
dims[i] = (hsize_t)n;
nelms *= (size_t)n;
}
@@ -4885,7 +4893,11 @@ static int read_data( const char* fname,
}
for(j = 0; j < nelms; j++) {
- fscanf( f, "%f",&val );
+ if(fscanf( f, "%f",&val ) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s\n", data_file );
+ HDfclose(f);
+ return -1;
+ } /* end if */
(*buf)[j] = val;
}
HDfclose(f);
diff --git a/hl/test/test_image.c b/hl/test/test_image.c
index 8ba0083..8bc6f95 100644
--- a/hl/test/test_image.c
+++ b/hl/test/test_image.c
@@ -603,8 +603,14 @@ static int test_generate(void)
*/
- fscanf( f, "%d %d %d", &imax, &jmax, &kmax );
- fscanf( f, "%f %f %f", &valex, &xmin, &xmax );
+ if(fscanf( f, "%d %d %d", &imax, &jmax, &kmax ) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+ if(fscanf( f, "%f %f %f", &valex, &xmin, &xmax ) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
/* Sanity check on scanned-in values */
if(imax < 1 || jmax < 1 || kmax < 1)
@@ -633,7 +639,10 @@ static int test_generate(void)
for ( i = 0; i < n_elements; i++ )
{
- fscanf( f, "%f ", &value );
+ if(fscanf( f, "%f ", &value ) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
data[i] = value;
}
HDfclose(f);
@@ -794,12 +803,35 @@ static int read_data(const char* fname, /*IN*/
goto out;
}
- fscanf(f, "%s", str);
- fscanf(f, "%d", &color_planes);
- fscanf(f, "%s", str);
- fscanf(f, "%d", &h);
- fscanf(f, "%s", str);
- fscanf(f, "%d", &w);
+ if(fscanf(f, "%s", str) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+
+ if(fscanf(f, "%d", &color_planes) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+
+ if(fscanf(f, "%s", str) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+
+ if(fscanf(f, "%d", &h) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+
+ if(fscanf(f, "%s", str) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
+
+ if(fscanf(f, "%d", &w) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
/* Check product for overflow */
if(w < 1 || h < 1 || color_planes < 1)
@@ -830,7 +862,10 @@ static int read_data(const char* fname, /*IN*/
/* Read data elements */
for(i = 0; i < n_elements; i++) {
- fscanf(f, "%d",&n);
+ if(fscanf(f, "%d", &n) < 0 && HDferror(f)) {
+ printf( "fscanf error in file %s.\n", data_file );
+ goto out;
+ } /* end if */
image_data[i] = (unsigned char)n;
} /* end for */