diff options
Diffstat (limited to 'hl/test/test_image.c')
-rw-r--r-- | hl/test/test_image.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 38f1830..814b351 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -13,8 +13,10 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include <limits.h> #include <stdlib.h> #include <string.h> + #include "h5hltest.h" #include "H5srcdir.h" #include "H5LTpublic.h" @@ -542,7 +544,7 @@ static int test_generate(void) int imax, jmax, kmax; int n_elements; float valex, xmin, xmax, value; - FILE *f; + FILE *f = NULL; const char *data_file = H5_get_srcdir_filename(DATA_FILE4); int i; int retval = FAIL; @@ -622,17 +624,20 @@ static int test_generate(void) if(n_elements > INT_MAX / (int)sizeof(float)) goto out; - data = (float *)HDmalloc((size_t)n_elements * sizeof( float )); - HDassert(data); - image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof( unsigned char )); - HDassert(image_data); + data = (float *)HDmalloc((size_t)n_elements * sizeof(float)); + if(NULL == data) + goto out; + image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char)); + if(NULL == image_data) + goto out; for ( i = 0; i < n_elements; i++ ) { fscanf( f, "%f ", &value ); data[i] = value; } - HDfclose( f ); + HDfclose(f); + f = NULL; /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char @@ -742,6 +747,8 @@ out: H5E_BEGIN_TRY { H5Fclose(fid); } H5E_END_TRY; + if(f) + HDfclose(f); H5_FAILED(); return retval; } @@ -794,9 +801,6 @@ static int read_data( const char* fname, /*IN*/ fscanf(f, "%s", str); fscanf(f, "%d", &w); - *width = (hsize_t)w; - *height = (hsize_t)h; - /* Check product for overflow */ if(w < 1 || h < 1 || color_planes < 1) goto out; @@ -813,13 +817,16 @@ static int read_data( const char* fname, /*IN*/ goto out; /* Release the buffer, if it was previously allocated */ - if(image_data) { + if(image_data) HDfree(image_data); - image_data = NULL; - } /* end if */ /* Allocate the image data buffer */ image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char)); + if(NULL == image_data) + goto out; + + *width = (hsize_t)w; + *height = (hsize_t)h; /* Read data elements */ for(i = 0; i < n_elements; i++) { |