summaryrefslogtreecommitdiffstats
path: root/hl/test/test_image.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-03-16 04:44:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-03-16 04:44:13 (GMT)
commit164b4c75341ee4aa31dcd47c189e415a36ae35e2 (patch)
tree121120c9d2df2d601730e4c371afbf5f82004f92 /hl/test/test_image.c
parent288c7760a4a55d56df7a9019a8522625e305b9b7 (diff)
downloadhdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.zip
hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.gz
hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.bz2
[svn-r24804] Description:
Brought changes from Coverity branch back to trunk, and cleaned up misc. other warnings & formatting issues: r20833: Fixed Coverity 667 and 668 with real integer overflow tests this time. r20834: Use HDstrncpy and HDstrncat. --gh r20835: Change to use strncpy - use base_len + 1 for line 156, use HDstrlen(path) + 1 for line 159 r20836: Fixed coverity 585 by casting output of fgetc() to a char. r20837: Changed sprintf calls to snprintf with size 1 less than the allocated buffer to address coverity issue #967. Tested on: Mac OSX/64 10.9.2 (amazon) w/C++, FORTRAN & parallel (too minor to require h5committest)
Diffstat (limited to 'hl/test/test_image.c')
-rw-r--r--hl/test/test_image.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c
index 38f1830..36dc734 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"
@@ -622,10 +624,12 @@ 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++ )
{
@@ -794,9 +798,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 +814,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++) {