summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-05-11 15:59:48 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-05-11 15:59:48 (GMT)
commitd38fe20df6bdb30906b18cf01ee644c44ed5b944 (patch)
treef9ebbcca3baaf76c5e4c4bcc5139e551cf3d6a0c
parent5ecebe5b9bc161153a3391bf32eb64687f675172 (diff)
downloadhdf5-d38fe20df6bdb30906b18cf01ee644c44ed5b944.zip
hdf5-d38fe20df6bdb30906b18cf01ee644c44ed5b944.tar.gz
hdf5-d38fe20df6bdb30906b18cf01ee644c44ed5b944.tar.bz2
[svn-r23695] Description:
Clean up warnings in H5Tconv.c (down to _only_ 9000 lines of output now!) Merge changes from Coverity branch back to trunk: r20684: Fix for coverity bug #1721 which was due to the fix for coverity bug #943. r20685: Use HDstrncpy. --gh r20761: Purpose: Fix valgrind issues Description: Free image_data and data as appropriate in test_image. r20762: Purpose: Fix coverity issue 600 Description: Add check for return value of H5O_close in H5Ocopy. Also cleaned up various warnings. r20763: Purpose: Fix valgrind issues with h5stat Description: Modified h5stat to free "iter" before exit, and free "hand" before exit if parse_command_line exits directly. r20764: fixed coverity issues: 69, 327, 614, 684, 685, 696, 697, 1681, 967, 826, 660, 80 r20765: Fixed coverity bug 668 Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning. No actual integer overflow tests are performed since it's just a test program but I did add a check that n_elements is >= 1. I also changed an error condition from doing its own close and returning -1 to "goto out;" like the rest of the program. r20766: Fixed coverity bug 667 Pulled x * y * z multiply out of malloc operand into a separate n_elements variable to quiet integer overflow warning. No actual integer overflow tests are performed since it's just a test program. Tested on: Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN (h5committest upcoming)
-rw-r--r--hl/test/test_image.c177
-rw-r--r--src/H5Ocopy.c27
-rw-r--r--src/H5R.c10
-rw-r--r--src/H5Tconv.c584
-rw-r--r--src/H5Tvlen.c10
-rw-r--r--src/H5private.h6
-rw-r--r--test/H5srcdir.h11
-rw-r--r--test/h5test.c20
-rw-r--r--tools/h5jam/getub.c2
-rw-r--r--tools/h5stat/h5stat.c337
-rw-r--r--tools/lib/h5diff_array.c6
-rw-r--r--tools/lib/h5tools.c16
-rw-r--r--tools/lib/h5tools_dump.c88
13 files changed, 731 insertions, 563 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c
index a4a10e4..76acef8 100644
--- a/hl/test/test_image.c
+++ b/hl/test/test_image.c
@@ -100,24 +100,34 @@ static int test_simple(void)
hssize_t npals;
/* 8-bit image */
- unsigned char buf1 [ WIDTH*HEIGHT ];
+ unsigned char *buf1 = NULL;
unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */
hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */
/* 24-bit image */
- unsigned char buf2 [ WIDTH*HEIGHT*3 ];
+ unsigned char *buf2 = NULL;
/* read data */
- unsigned char buf1_out [ WIDTH*HEIGHT ];
- unsigned char buf2_out [ WIDTH*HEIGHT*3 ];
+ unsigned char *buf1_out = NULL;
+ unsigned char *buf2_out = NULL;
unsigned char pal_out[ PAL_ENTRIES * 3 ]; /* palette array */
hsize_t pal_dims_out[2]; /* palette dimensions */
+ /* Allocate image buffers */
+ buf1 = (unsigned char *)HDmalloc(WIDTH * HEIGHT);
+ HDassert(buf1);
+ buf2 = (unsigned char *)HDmalloc(WIDTH * HEIGHT * 3);
+ HDassert(buf2);
+ buf1_out = (unsigned char *)HDmalloc(WIDTH * HEIGHT);
+ HDassert(buf1_out);
+ buf2_out = (unsigned char *)HDmalloc(WIDTH * HEIGHT * 3);
+ HDassert(buf2_out);
+
/* create an image */
space = WIDTH*HEIGHT / PAL_ENTRIES;
for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ )
{
- buf1[i] = n;
+ buf1[i] = (unsigned char)n;
if ( j > space )
{
n++;
@@ -126,17 +136,13 @@ static int test_simple(void)
}
-
/* create an image */
space = WIDTH*HEIGHT / 256;
for (i=0, j=0, n=0; i < WIDTH*HEIGHT*3; i+=3, j++ )
{
- unsigned char r, g, b;
-
- r = n; g = 0; b = 255-n;
- buf2[i] = r;
- buf2[i+1] = g;
- buf2[i+2] = b;
+ buf2[i] = (unsigned char)n;
+ buf2[i+1] = 0;
+ buf2[i+2] = (unsigned char)(255 - n);
if ( j > space )
{
n++;
@@ -150,9 +156,9 @@ static int test_simple(void)
*/
for ( i=0, n=0; i<PAL_ENTRIES*3; i+=3, n++)
{
- pal[i] =n; /* red */
+ pal[i] =(unsigned char)n; /* red */
pal[i+1]=0; /* green */
- pal[i+2]=255-n; /* blue */
+ pal[i+2]=(unsigned char)(255 - n); /* blue */
}
/* Create a new HDF5 file using default properties. */
@@ -294,6 +300,14 @@ static int test_simple(void)
/* error zone, gracefully close */
out:
+ if(buf1)
+ HDfree(buf1);
+ if(buf2)
+ HDfree(buf2);
+ if(buf1_out)
+ HDfree(buf1_out);
+ if(buf2_out)
+ HDfree(buf2_out);
H5E_BEGIN_TRY {
H5Fclose(fid);
} H5E_END_TRY;
@@ -367,7 +381,7 @@ static int test_data(void)
*/
/* read a PAL file */
- if (read_palette(PAL2_FILE, rgb, sizeof(rgb))<0)
+ if (read_palette(PAL2_FILE, rgb, (sizeof(rgb) / sizeof(rgb[0]))) < 0)
goto out;
/* transfer to the HDF5 buffer */
@@ -393,7 +407,7 @@ static int test_data(void)
*/
/* read a PAL file */
- if (read_palette(PAL3_FILE, rgb, sizeof(rgb))<0)
+ if (read_palette(PAL3_FILE, rgb, (sizeof(rgb) / sizeof(rgb[0]))) < 0)
goto out;
/* transfer to the HDF5 buffer */
@@ -422,9 +436,9 @@ static int test_data(void)
*/
for ( i=0, n=0; i<256*3; i+=3, n++)
{
- pal[i] =n;
+ pal[i] =(unsigned char)n;
pal[i+1]=0;
- pal[i+2]=255-n;
+ pal[i+2]=(unsigned char)(255 - n);
}
/* make a palette */
@@ -478,13 +492,21 @@ static int test_data(void)
if (H5Fclose(fid)<0)
goto out;
+ /* Release memory buffer */
+ HDfree(image_data);
+
return 0;
/* error zone, gracefully close */
out:
+ /* Release memory buffer */
+ if(image_data)
+ HDfree(image_data);
+
H5E_BEGIN_TRY {
H5Fclose(fid);
} H5E_END_TRY;
+
H5_FAILED();
return FAIL;
}
@@ -509,6 +531,7 @@ static int test_generate(void)
hsize_t pal_dims[2] = { 256, 3 };
float *data;
int imax, jmax, kmax;
+ int n_elements;
float valex, xmin, xmax, value;
FILE *f;
const char *data_file = H5_get_srcdir_filename(DATA_FILE4);
@@ -530,8 +553,7 @@ static int test_generate(void)
if ( f == NULL )
{
printf( "Could not find file %s. Try set $srcdir \n", data_file );
- H5Fclose(fid);
- return -1;
+ goto out;
}
/*
@@ -573,10 +595,30 @@ static int test_generate(void)
fscanf( f, "%d %d %d", &imax, &jmax, &kmax );
fscanf( f, "%f %f %f", &valex, &xmin, &xmax );
- data = (float*) HDmalloc ( imax * jmax * kmax * sizeof( float ));
- image_data = (unsigned char*) HDmalloc ( imax * jmax * kmax * sizeof( unsigned char ));
+ /* Sanity check on scanned-in values */
+ if(imax < 1 || jmax < 1 || kmax < 1)
+ goto out;
- for ( i = 0; i < imax * jmax * kmax; i++ )
+ /* Test product for integer overflow */
+ if(imax > INT_MAX / jmax)
+ goto out;
+ if(imax * jmax > INT_MAX / kmax)
+ goto out;
+
+ n_elements = imax * jmax * kmax;
+
+ /* Test buffer sizes for overflow */
+ if(n_elements > INT_MAX / (int)sizeof(unsigned char))
+ goto out;
+ 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);
+
+ for ( i = 0; i < n_elements; i++ )
{
fscanf( f, "%f ", &value );
data[i] = value;
@@ -591,10 +633,8 @@ static int test_generate(void)
TESTING2("make indexed image from all the data");
- for ( i = 0; i < imax * jmax * kmax; i++ )
- {
+ for ( i = 0; i < n_elements; i++ )
image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / (xmax - xmin ));
- }
/* Make the image */
if ((H5IMmake_image_8bit(fid,"All data",(hsize_t)imax,(hsize_t)jmax,image_data))<0)
@@ -610,7 +650,7 @@ static int test_generate(void)
TESTING2("make indexed image from land data");
- for ( i = 0; i < imax * jmax * kmax; i++ )
+ for ( i = 0; i < n_elements; i++ )
{
if ( data[i] < 0 )
image_data[i] = 0;
@@ -632,7 +672,7 @@ static int test_generate(void)
TESTING2("make indexed image from sea data");
- for ( i = 0; i < imax * jmax * kmax; i++ )
+ for ( i = 0; i < n_elements; i++ )
{
if ( data[i] > 0 )
image_data[i] = 0;
@@ -675,12 +715,21 @@ static int test_generate(void)
if (H5Fclose(fid)<0)
goto out;
+ /* Release memory buffers */
+ HDfree(data);
+ HDfree(image_data);
+
/* Indicate success */
return 0;
/* error zone, gracefully close */
out:
- HDfree(data);
+ /* Release memory buffers */
+ if(data)
+ HDfree(data);
+ if(image_data)
+ HDfree(image_data);
+
H5E_BEGIN_TRY {
H5Fclose(fid);
} H5E_END_TRY;
@@ -713,51 +762,71 @@ static int read_data( const char* fname, /*IN*/
int i, n;
int color_planes;
char str[20];
- FILE *f;
+ FILE *f = NULL;
int w, h;
+ int n_elements;
const char *data_file = H5_get_srcdir_filename(fname);
+ int ret_val = -1;
/*-------------------------------------------------------------------------
* read
*-------------------------------------------------------------------------
*/
- f = HDfopen(data_file, "r");
- if ( f == NULL )
- {
+ if(NULL == (f = HDfopen(data_file, "r"))) {
printf( "Could not open file %s. Try set $srcdir \n", data_file );
- return -1;
+ 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);
+ 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);
*width = (hsize_t)w;
*height = (hsize_t)h;
- if ( image_data )
- {
- HDfree( image_data );
- image_data=NULL;
- }
+ /* Check product for overflow */
+ if(w < 1 || h < 1 || color_planes < 1)
+ goto out;
+ if(w > INT_MAX / h)
+ goto out;
+ if(w * h > INT_MAX / color_planes)
+ goto out;
- image_data = (unsigned char*) HDmalloc (w * h * color_planes * sizeof( unsigned char ));
+ /* Compute buffer size */
+ n_elements = w * h * color_planes;
- for (i = 0; i < h * w * color_planes ; i++)
- {
- fscanf( f, "%d",&n );
+ /* Check buffer size for overflow */
+ if(n_elements > INT_MAX / (int)sizeof(unsigned char))
+ goto out;
+
+ /* Release the buffer, if it was previously allocated */
+ 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));
+
+ /* Read data elements */
+ for(i = 0; i < n_elements; i++) {
+ fscanf(f, "%d",&n);
image_data[i] = (unsigned char)n;
- }
- HDfclose(f);
+ } /* end for */
- return 1;
+ /* Indicate success */
+ ret_val = 1;
-}
+out:
+ if(f)
+ HDfclose(f);
+ return ret_val;
+} /* end read_data() */
/*-------------------------------------------------------------------------
@@ -882,6 +951,6 @@ static int read_palette(const char* fname,
/* close file */
HDfclose(file);
- return nentries;
+ return (int)nentries;
}
diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c
index dc79e47..fc82407 100644
--- a/src/H5Ocopy.c
+++ b/src/H5Ocopy.c
@@ -286,9 +286,9 @@ H5Ocopy(hid_t src_loc_id, const char *src_name, hid_t dst_loc_id,
done:
if(loc_found && H5G_loc_free(&src_loc) < 0)
- HDONE_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "can't free location")
- if(obj_open)
- H5O_close(&src_oloc);
+ HDONE_ERROR(H5E_OHDR, H5E_CANTRELEASE, FAIL, "can't free location")
+ if(obj_open && H5O_close(&src_oloc) < 0)
+ HDONE_ERROR(H5E_OHDR, H5E_CLOSEERROR, FAIL, "unable to release object header")
FUNC_LEAVE_API(ret_value)
} /* end H5Ocopy() */
@@ -669,7 +669,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out*/,
} /* end if */
/* Add in destination's object header size now */
- dst_oh_size += H5O_SIZEOF_HDR(oh_dst);
+ dst_oh_size += (uint64_t)H5O_SIZEOF_HDR(oh_dst);
/* Allocate space for chunk in destination file */
if(HADDR_UNDEF == (oh_dst->chunk[0].addr = H5MF_alloc(oloc_dst->file, H5FD_MEM_OHDR, dxpl_id, (hsize_t)dst_oh_size)))
@@ -1284,7 +1284,8 @@ H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, hid_t dxpl_id,
H5O_loc_t dst_oloc; /* Copied object object location */
H5O_loc_t src_oloc; /* Temporary object location for source object */
H5G_loc_t dst_root_loc; /* The location of root group of the destination file */
- uint8_t *p; /* Pointer to OID to store */
+ const uint8_t *q; /* Pointer to source OID to store */
+ uint8_t *p; /* Pointer to destination OID to store */
size_t i; /* Local index variable */
herr_t ret_value = SUCCEED;
@@ -1318,8 +1319,8 @@ H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, hid_t dxpl_id,
/* Making equivalent references in the destination file */
for(i = 0; i < ref_count; i++) {
/* Set up for the object copy for the reference */
- p = (uint8_t *)(&src_ref[i]);
- H5F_addr_decode(src_oloc.file, (const uint8_t **)&p, &(src_oloc.addr));
+ q = (uint8_t *)(&src_ref[i]);
+ H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(src_oloc.addr));
dst_oloc.addr = HADDR_UNDEF;
/* Attempt to copy object from source to destination file */
@@ -1347,9 +1348,9 @@ H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, hid_t dxpl_id,
/* Making equivalent references in the destination file */
for(i = 0; i < ref_count; i++) {
/* Get the heap ID for the dataset region */
- p = (uint8_t *)(&src_ref[i]);
- H5F_addr_decode(src_oloc.file, (const uint8_t **)&p, &(hobjid.addr));
- INT32DECODE(p, hobjid.idx);
+ q = (const uint8_t *)(&src_ref[i]);
+ H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(hobjid.addr));
+ UINT32DECODE(q, hobjid.idx);
if(hobjid.addr != (haddr_t)0) {
/* Get the dataset region from the heap (allocate inside routine) */
@@ -1357,8 +1358,8 @@ H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, hid_t dxpl_id,
HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL, "Unable to read dataset region information")
/* Get the object oid for the dataset */
- p = (uint8_t *)buf;
- H5F_addr_decode(src_oloc.file, (const uint8_t **)&p, &(src_oloc.addr));
+ q = (const uint8_t *)buf;
+ H5F_addr_decode(src_oloc.file, (const uint8_t **)&q, &(src_oloc.addr));
dst_oloc.addr = HADDR_UNDEF;
/* copy the object pointed by the ref to the destination */
@@ -1384,7 +1385,7 @@ H5O_copy_expand_ref(H5F_t *file_src, void *_src_ref, hid_t dxpl_id,
/* Set the dataset region reference info for the destination file */
p = (uint8_t *)(&dst_ref[i]);
H5F_addr_encode(dst_oloc.file, &p, hobjid.addr);
- INT32ENCODE(p, hobjid.idx);
+ UINT32ENCODE(p, hobjid.idx);
/* Free the buffer allocated in H5HG_read() */
H5MM_xfree(buf);
diff --git a/src/H5R.c b/src/H5R.c
index d45947b..bf8ffba 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -295,7 +295,7 @@ H5R_create(void *_ref, H5G_loc_t *loc, const char *name, H5R_type_t ref_type, H5
/* Serialize the heap ID and index for storage in the file */
p = (uint8_t *)ref;
H5F_addr_encode(loc->oloc->file, &p, hobjid.addr);
- INT32ENCODE(p, hobjid.idx);
+ UINT32ENCODE(p, hobjid.idx);
/* Free the buffer we serialized data in */
H5MM_xfree(buf);
@@ -439,7 +439,7 @@ H5R_dereference(H5F_t *file, hid_t oapl_id, hid_t dxpl_id, H5R_type_t ref_type,
/* Get the heap ID for the dataset region */
p = (const uint8_t *)_ref;
H5F_addr_decode(oloc.file, &p, &(hobjid.addr));
- INT32DECODE(p, hobjid.idx);
+ UINT32DECODE(p, hobjid.idx);
/* Get the dataset region from the heap (allocate inside routine) */
if(NULL == (buf = (uint8_t *)H5HG_read(oloc.file, dxpl_id, &hobjid, NULL, NULL)))
@@ -637,7 +637,7 @@ H5R_get_region(H5F_t *file, hid_t dxpl_id, const void *_ref)
/* Get the heap ID for the dataset region */
p = (const uint8_t *)_ref;
H5F_addr_decode(oloc.file, &p, &(hobjid.addr));
- INT32DECODE(p, hobjid.idx);
+ UINT32DECODE(p, hobjid.idx);
/* Get the dataset region from the heap (allocate inside routine) */
if((buf = (uint8_t *)H5HG_read(oloc.file, dxpl_id, &hobjid, NULL, NULL)) == NULL)
@@ -772,7 +772,7 @@ H5R_get_obj_type(H5F_t *file, hid_t dxpl_id, H5R_type_t ref_type,
/* Get the heap ID for the dataset region */
p = (const uint8_t *)_ref;
H5F_addr_decode(oloc.file, &p, &(hobjid.addr));
- INT32DECODE(p, hobjid.idx);
+ UINT32DECODE(p, hobjid.idx);
/* Get the dataset region from the heap (allocate inside routine) */
if((buf = (uint8_t *)H5HG_read(oloc.file, dxpl_id, &hobjid, NULL, NULL)) == NULL)
@@ -916,7 +916,7 @@ H5R_get_name(H5F_t *f, hid_t lapl_id, hid_t dxpl_id, hid_t id, H5R_type_t ref_ty
/* Get the heap ID for the dataset region */
p = (const uint8_t *)_ref;
H5F_addr_decode(oloc.file, &p, &(hobjid.addr));
- INT32DECODE(p, hobjid.idx);
+ UINT32DECODE(p, hobjid.idx);
/* Get the dataset region from the heap (allocate inside routine) */
if((buf = (uint8_t *)H5HG_read(oloc.file, dxpl_id, &hobjid, NULL, NULL)) == NULL)
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index b732817..ce0f736 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -189,7 +189,7 @@
* to the destination. SLU - 2005/06/29
*/
#define H5T_CONV_Xx_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if (*(S) > (DT)(D_MAX)) { \
+ if (*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -198,7 +198,7 @@
else if(except_ret == H5T_CONV_ABORT) \
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
/* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
- } else if (*(S) < (DT)(D_MIN)) { \
+ } else if (*(S) < (ST)(D_MIN)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -211,16 +211,16 @@
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Xx_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if (*(S) > (DT)(D_MAX)) { \
+ if (*(S) > (ST)(D_MAX)) { \
*(D) = (DT)(D_MAX); \
- } else if (*(S) < (DT)(D_MIN)) { \
+ } else if (*(S) < (ST)(D_MIN)) { \
*(D) = (DT)(D_MIN); \
} else \
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Ux_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if (*(S) > (DT)(D_MAX)) { \
+ if (*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -233,7 +233,7 @@
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Ux_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if (*(S) > (DT)(D_MAX)) { \
+ if (*(S) > (ST)(D_MAX)) { \
*(D) = (DT)(D_MAX); \
} else \
*(D) = (DT)(*(S)); \
@@ -241,7 +241,7 @@
#define H5T_CONV_sS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)<=sizeof(DT)); \
- H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_sU_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
@@ -266,7 +266,7 @@
#define H5T_CONV_sU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)<=sizeof(DT)); \
- H5T_CONV(H5T_CONV_sU, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_sU, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_uS_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
@@ -283,7 +283,7 @@
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_uS_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if (sizeof(ST)==sizeof(DT) && *(S) > (D_MAX)) { \
+ if (sizeof(ST)==sizeof(DT) && *(S) > (DT)(D_MAX)) { \
*(D) = (D_MAX); \
} else \
*(D) = (DT)(*(S)); \
@@ -291,17 +291,17 @@
#define H5T_CONV_uS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)<=sizeof(DT)); \
- H5T_CONV(H5T_CONV_uS, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_uS, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_uU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)<=sizeof(DT)); \
- H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_Ss(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)>=sizeof(DT)); \
- H5T_CONV(H5T_CONV_Xx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Xx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_Su_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
@@ -314,7 +314,7 @@
else if(except_ret == H5T_CONV_ABORT) \
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
/* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
- } else if (sizeof(ST)>sizeof(DT) && *(S) > (DT)(D_MAX)) { \
+ } else if (sizeof(ST)>sizeof(DT) && *(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -329,7 +329,7 @@
#define H5T_CONV_Su_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
if(*(S) < 0) \
*(D) = 0; \
- else if (sizeof(ST)>sizeof(DT) && *(S) > (DT)(D_MAX)) \
+ else if (sizeof(ST)>sizeof(DT) && *(S) > (ST)(D_MAX)) \
*(D) = (DT)(D_MAX); \
else \
*(D) = (DT)(*(S)); \
@@ -337,17 +337,17 @@
#define H5T_CONV_Su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)>=sizeof(DT)); \
- H5T_CONV(H5T_CONV_Su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_Us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)>=sizeof(DT)); \
- H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_Uu(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)>=sizeof(DT)); \
- H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_su_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
@@ -374,12 +374,12 @@
#define H5T_CONV_su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)==sizeof(DT)); \
- H5T_CONV(H5T_CONV_su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_us_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
/* Assumes memory format of unsigned & signed integers is same */ \
- if (*(S) > (DT)(D_MAX)) { \
+ if (*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -393,7 +393,7 @@
}
#define H5T_CONV_us_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
/* Assumes memory format of unsigned & signed integers is same */ \
- if(*(S) > (DT)(D_MAX)) \
+ if(*(S) > (ST)(D_MAX)) \
*(D) = (DT)(D_MAX); \
else \
*(D) = (DT)(*(S)); \
@@ -401,19 +401,19 @@
#define H5T_CONV_us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)==sizeof(DT)); \
- H5T_CONV(H5T_CONV_us, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_us, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_CONV_fF(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)<=sizeof(DT)); \
- H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
/* Same as H5T_CONV_Xx_CORE, except that instead of using D_MAX and D_MIN
* when an overflow occurs, use the 'float' infinity values.
*/
#define H5T_CONV_Ff_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if(*(S) > (DT)(D_MAX)) { \
+ if(*(S) > (ST)(D_MAX)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -422,7 +422,7 @@
else if(except_ret == H5T_CONV_ABORT) \
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
/* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
- } else if (*(S) < (DT)(D_MIN)) { \
+ } else if (*(S) < (ST)(D_MIN)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -435,9 +435,9 @@
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Ff_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if(*(S) > (DT)(D_MAX)) \
+ if(*(S) > (ST)(D_MAX)) \
*(D) = (H5T_NATIVE_FLOAT_POS_INF_g); \
- else if (*(S) < (DT)(D_MIN)) \
+ else if (*(S) < (ST)(D_MIN)) \
*(D) = (H5T_NATIVE_FLOAT_NEG_INF_g); \
else \
*(D) = (DT)(*(S)); \
@@ -445,7 +445,7 @@
#define H5T_CONV_Ff(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
HDcompile_assert(sizeof(ST)>=sizeof(DT)); \
- H5T_CONV(H5T_CONV_Ff, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Ff, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N) \
}
#define H5T_HI_LO_BIT_SET(TYP, V, LO, HI) { \
@@ -455,8 +455,8 @@
\
count = 0; \
for(u = 0; u < sizeof(TYP); u++) { \
- count = ((sizeof(TYP) - 1) - u) * 8; \
- p = ((V) >> count) & 0xff; \
+ count = (((unsigned)sizeof(TYP) - 1) - u) * 8; \
+ p = (unsigned char)((V) >> count); \
if(p > 0) { \
if(p & 0x80) \
count += 7; \
@@ -480,7 +480,7 @@
\
count = 0; \
for(u = 0; u < sizeof(TYP); u++) { \
- p = ((V) >> (u * 8)) & 0xff; \
+ p = (unsigned char)((V) >> (u * 8)); \
if(p > 0) { \
count = u * 8; \
\
@@ -536,7 +536,7 @@
}
#define H5T_CONV_xF(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
- H5T_CONV(H5T_CONV_xF, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_xF, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, Y) \
}
/* Quincey added the condition branch (else if (*(S) != (ST)((DT)(*(S))))).
@@ -544,11 +544,11 @@
* of "INT_MAX". Compilers do roundup making this value "INT_MAX+1". This branch
* is to check that situation and return exception for some compilers, mainly GCC.
* The branch if (*(S) > (DT)(D_MAX) || (sprec < dprec && *(S) ==
- * (DT)(D_MAX))) is for some compilers like Sun, HP, IBM, and SGI where under
+ * (ST)(D_MAX))) is for some compilers like Sun, HP, IBM, and SGI where under
* the same situation the "int" doesn't overflow. SLU - 2005/9/12
*/
#define H5T_CONV_Fx_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if(*(S) > (DT)(D_MAX) || (sprec < dprec && *(S) == (DT)(D_MAX))) { \
+ if(*(S) > (ST)(D_MAX) || (sprec < dprec && *(S) == (ST)(D_MAX))) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -557,7 +557,7 @@
else if(except_ret == H5T_CONV_ABORT) \
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
/* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
- } else if (*(S) < (DT)(D_MIN)) { \
+ } else if (*(S) < (ST)(D_MIN)) { \
H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, \
src_id, dst_id, S, D, cb_struct.user_data); \
if(except_ret == H5T_CONV_UNHANDLED) \
@@ -580,28 +580,31 @@
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Fx_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
- if(*(S) > (DT)(D_MAX)) \
+ if(*(S) > (ST)(D_MAX)) \
*(D) = (DT)(D_MAX); \
- else if(*(S) < (DT)(D_MIN)) \
+ else if(*(S) < (ST)(D_MIN)) \
*(D) = (DT)(D_MIN); \
else \
*(D) = (DT)(*(S)); \
}
#define H5T_CONV_Fx(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) { \
- H5T_CONV(H5T_CONV_Fx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX) \
+ H5T_CONV(H5T_CONV_Fx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, Y) \
}
/* Since all "no exception" cores do the same thing (assign the value in the
* source location to the destination location, using casting), use one "core"
* to do them all.
*/
+#ifndef H5_WANT_DCONV_EXCEPTION
#define H5T_CONV_NO_EXCEPT_CORE(S,D,ST,DT,D_MIN,D_MAX) { \
*(D) = (DT)(*(S)); \
}
+#endif /* H5_WANT_DCONV_EXCEPTION */
+
/* The main part of every integer hardware conversion macro */
-#define H5T_CONV(GUTS,STYPE,DTYPE,ST,DT,D_MIN,D_MAX) \
+#define H5T_CONV(GUTS,STYPE,DTYPE,ST,DT,D_MIN,D_MAX,PREC) \
{ \
herr_t ret_value=SUCCEED; /* Return value */ \
\
@@ -609,13 +612,11 @@
\
{ \
size_t elmtno; /*element number */ \
- size_t sprec; /*source precision */ \
- size_t dprec; /*destination precision */ \
+ H5T_CONV_DECL_PREC(PREC) /*declare precision variables, or not */ \
uint8_t *src_buf; /*'raw' source buffer */ \
uint8_t *dst_buf; /*'raw' destination buffer */ \
ST *src, *s; /*source buffer */ \
DT *dst, *d; /*destination buffer */ \
- H5T_class_t tclass; /*datatype's class */ \
H5T_t *st, *dt; /*datatype descriptors */ \
ST src_aligned; /*source aligned type */ \
DT dst_aligned; /*destination aligned type */ \
@@ -647,8 +648,8 @@
case H5T_CONV_CONV: \
/* Initialize source & destination strides */ \
if (buf_stride) { \
- assert(buf_stride>=sizeof(ST)); \
- assert(buf_stride>=sizeof(DT)); \
+ HDassert(buf_stride >= sizeof(ST)); \
+ HDassert(buf_stride >= sizeof(DT)); \
s_stride = d_stride = (ssize_t)buf_stride; \
} else { \
s_stride = sizeof(ST); \
@@ -659,11 +660,11 @@
s_mv = H5T_NATIVE_##STYPE##_ALIGN_g>1 && \
((size_t)buf%H5T_NATIVE_##STYPE##_ALIGN_g || \
/* Cray */ ((size_t)((ST*)buf)!=(size_t)buf) || \
- s_stride%H5T_NATIVE_##STYPE##_ALIGN_g); \
+ (size_t)s_stride%H5T_NATIVE_##STYPE##_ALIGN_g); \
d_mv = H5T_NATIVE_##DTYPE##_ALIGN_g>1 && \
((size_t)buf%H5T_NATIVE_##DTYPE##_ALIGN_g || \
/* Cray */ ((size_t)((DT*)buf)!=(size_t)buf) || \
- d_stride%H5T_NATIVE_##DTYPE##_ALIGN_g); \
+ (size_t)d_stride%H5T_NATIVE_##DTYPE##_ALIGN_g); \
CI_INC_SRC(s_mv) \
CI_INC_DST(d_mv) \
\
@@ -679,19 +680,7 @@
if(NULL == (st = (H5T_t *)H5I_object(src_id)) || NULL == (dt = (H5T_t *)H5I_object(dst_id))) \
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to dereference datatype object ID") \
\
- /* Get source & destination precisions into a variable */ \
- tclass = st->shared->type; \
- HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT); \
- if(tclass == H5T_INTEGER) \
- sprec = st->shared->u.atomic.prec; \
- else \
- sprec = 1 + st->shared->u.atomic.u.f.msize; \
- tclass = dt->shared->type; \
- HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT); \
- if(tclass == H5T_INTEGER) \
- dprec = dt->shared->u.atomic.prec; \
- else \
- dprec = 1 + dt->shared->u.atomic.u.f.msize; \
+ H5T_CONV_SET_PREC(PREC) /*init precision variables, or not */ \
\
/* The outer loop of the type conversion macro, controlling which */ \
/* direction the buffer is walked */ \
@@ -701,21 +690,21 @@
/* Compute the number of "safe" destination elements at */ \
/* the end of the buffer (Those which don't overlap with */ \
/* any source elements at the beginning of the buffer) */ \
- safe=nelmts-(((nelmts*s_stride)+(d_stride-1))/d_stride); \
+ safe = nelmts - (((nelmts * (size_t)s_stride) + (size_t)(d_stride - 1)) / (size_t)d_stride); \
\
/* If we're down to the last few elements, just wrap up */ \
/* with a "real" reverse copy */ \
if(safe<2) { \
- src = (ST *)(src_buf = (uint8_t*)buf+(nelmts-1)*s_stride); \
- dst = (DT *)(dst_buf = (uint8_t*)buf+(nelmts-1)*d_stride); \
+ src = (ST *)(src_buf = (uint8_t *)buf + (nelmts - 1) * (size_t)s_stride); \
+ dst = (DT *)(dst_buf = (uint8_t *)buf + (nelmts - 1) * (size_t)d_stride); \
s_stride = -s_stride; \
d_stride = -d_stride; \
\
safe=nelmts; \
} /* end if */ \
else { \
- src = (ST *)(src_buf = (uint8_t*)buf+(nelmts-safe)*s_stride); \
- dst = (DT *)(dst_buf = (uint8_t*)buf+(nelmts-safe)*d_stride); \
+ src = (ST *)(src_buf = (uint8_t *)buf + (nelmts - safe) * (size_t)s_stride); \
+ dst = (DT *)(dst_buf = (uint8_t *)buf + (nelmts - safe) * (size_t)d_stride); \
} /* end else */ \
} /* end if */ \
else { \
@@ -757,6 +746,36 @@ done: \
FUNC_LEAVE_NOAPI(ret_value) \
}
+/* Declare the source & destination precision variables */
+#define H5T_CONV_DECL_PREC(PREC) H5_GLUE(H5T_CONV_DECL_PREC_, PREC)
+
+#define H5T_CONV_DECL_PREC_Y \
+ size_t sprec; /*source precision */ \
+ size_t dprec; /*destination precision */ \
+ H5T_class_t tclass; /*datatype's class */
+
+#define H5T_CONV_DECL_PREC_N /*no precision variables */
+
+/* Initialize the source & destination precision variables */
+#define H5T_CONV_SET_PREC(PREC) H5_GLUE(H5T_CONV_SET_PREC_, PREC)
+
+#define H5T_CONV_SET_PREC_Y \
+ /* Get source & destination precisions into a variable */ \
+ tclass = st->shared->type; \
+ HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT); \
+ if(tclass == H5T_INTEGER) \
+ sprec = st->shared->u.atomic.prec; \
+ else \
+ sprec = 1 + st->shared->u.atomic.u.f.msize; \
+ tclass = dt->shared->type; \
+ HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT); \
+ if(tclass == H5T_INTEGER) \
+ dprec = dt->shared->u.atomic.prec; \
+ else \
+ dprec = 1 + dt->shared->u.atomic.u.f.msize;
+
+#define H5T_CONV_SET_PREC_N /*don't init precision variables */
+
/* Macro defining action on source data which needs to be aligned (before main action) */
#define H5T_CONV_LOOP_PRE_SALIGN(ST) { \
HDmemcpy(&src_aligned, src, sizeof(ST)); \
@@ -903,7 +922,7 @@ typedef struct H5T_conv_struct_t {
/* Conversion data for H5T__conv_enum() */
typedef struct H5T_enum_struct_t {
int base; /*lowest `in' value */
- int length; /*num elements in arrays */
+ unsigned length; /*num elements in arrays */
int *src2dst; /*map from src to dst index */
} H5T_enum_struct_t;
@@ -1085,6 +1104,15 @@ H5T__conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
break;
+ case H5T_NO_CLASS:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_OPAQUE:
+ case H5T_COMPOUND:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
}
@@ -1402,6 +1430,9 @@ H5T__conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
H5_SWAP_BYTES(buf, 7, 8);
} /* end for */
break;
+
+ default:
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "invalid conversion size")
} /* end switch */
break;
@@ -1487,6 +1518,16 @@ H5T__conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
} /* end if */
break;
+ case H5T_NO_CLASS:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_OPAQUE:
+ case H5T_COMPOUND:
+ case H5T_REFERENCE:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
} /* end switch */
@@ -1543,7 +1584,7 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
{
uint8_t *buf = (uint8_t*)_buf;
H5T_t *src = NULL, *dst = NULL; /*source and dest datatypes */
- int direction; /*direction of traversal */
+ ssize_t direction; /*direction of traversal */
size_t elmtno; /*element number */
size_t olap; /*num overlapping elements */
size_t half_size; /*1/2 of total size for swapping*/
@@ -1620,6 +1661,9 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
src_rev = (uint8_t *)H5MM_calloc(src->shared->size);
/* The conversion loop */
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
for(elmtno = 0; elmtno < nelmts; elmtno++) {
/*
@@ -1703,6 +1747,9 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
H5T__bit_set(d, (size_t)0, dst->shared->u.atomic.offset, TRUE);
break;
+ case H5T_PAD_ERROR:
+ case H5T_PAD_BACKGROUND:
+ case H5T_NPAD:
default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported LSB padding")
} /* end switch */
@@ -1715,6 +1762,10 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
case H5T_PAD_ONE:
H5T__bit_set(d, msb_pad_offset, 8 * dst->shared->size - msb_pad_offset, TRUE);
break;
+
+ case H5T_PAD_ERROR:
+ case H5T_PAD_BACKGROUND:
+ case H5T_NPAD:
default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported MSB padding")
} /* end switch */
@@ -1739,12 +1790,12 @@ H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
if(d == dbuf)
HDmemcpy(dp, d, dst->shared->size);
if(buf_stride) {
- sp += direction * buf_stride;
- dp += direction * buf_stride;
+ sp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
+ dp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
} /* end if */
else {
- sp += direction * src->shared->size;
- dp += direction * dst->shared->size;
+ sp += direction * (ssize_t)src->shared->size; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
+ dp += direction * (ssize_t)dst->shared->size; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
} /* end else */
} /* end for */
@@ -2062,20 +2113,6 @@ H5T__conv_struct_subset(const H5T_cdata_t *cdata)
* Programmer: Robb Matzke
* Thursday, January 22, 1998
*
- * Modifications:
- * Robb Matzke, 1999-06-16
- * Added support for non-zero strides. If BUF_STRIDE is
- * non-zero then convert one value at each memory location
- * advancing BUF_STRIDE bytes each time; otherwise assume
- * both source and destination values are packed.
- *
- * Robb Matzke, 2000-05-17
- * Added the BKG_STRIDE argument to fix a design bug. If
- * BUF_STRIDE and BKG_STRIDE are both non-zero then each
- * data element converted will be placed temporarily at a
- * multiple of BKG_STRIDE in the BKG buffer; otherwise the
- * BKG buffer is assumed to be a packed array of destination
- * datatype.
*-------------------------------------------------------------------------
*/
herr_t
@@ -2091,7 +2128,8 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
H5T_cmemb_t *src_memb = NULL; /*source struct member descript.*/
H5T_cmemb_t *dst_memb = NULL; /*destination struct memb desc. */
size_t offset; /*byte offset wrt struct */
- size_t src_delta; /*source stride */
+ ssize_t src_delta; /*source stride */
+ ssize_t bkg_delta; /*background stride */
size_t elmtno;
unsigned u; /*counters */
int i; /*counters */
@@ -2149,17 +2187,22 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* Direction of conversion and striding through background.
*/
if(buf_stride) {
- src_delta = buf_stride;
- if(!bkg_stride)
- bkg_stride = dst->shared->size;
+ H5_ASSIGN_OVERFLOW(src_delta, buf_stride, size_t, ssize_t);
+ if(!bkg_stride) {
+ H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t);
+ } /* end if */
+ else
+ H5_ASSIGN_OVERFLOW(bkg_delta, bkg_stride, size_t, ssize_t);
} /* end if */
else if(dst->shared->size <= src->shared->size) {
- src_delta = src->shared->size;
- bkg_stride = dst->shared->size;
+ H5_ASSIGN_OVERFLOW(src_delta, src->shared->size, size_t, ssize_t);
+ H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t);
} /* end else-if */
else {
- src_delta = -(int)src->shared->size; /*overflow shouldn't be possible*/
- bkg_stride = -(int)dst->shared->size; /*overflow shouldn't be possible*/
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ src_delta = -(ssize_t)src->shared->size;
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
+ bkg_delta = -(ssize_t)dst->shared->size;
xbuf += (nelmts - 1) * src->shared->size;
xbkg += (nelmts - 1) * dst->shared->size;
} /* end else */
@@ -2204,7 +2247,8 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* yet). Then copy the member to the destination offset in the
* background buffer.
*/
- for(i = src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
+ H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
+ for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
if(src2dst[i] < 0)
continue; /*subsetting*/
src_memb = src->shared->u.compnd.memb + i;
@@ -2229,12 +2273,12 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* Update pointers
*/
xbuf += src_delta;
- xbkg += bkg_stride;
+ xbkg += bkg_delta;
} /* end for */
- /* If the bkg_stride was set to -(dst->shared->size), make it positive now */
+ /* If the bkg_delta was set to -(dst->shared->size), make it positive now */
if(buf_stride == 0 && dst->shared->size > src->shared->size)
- bkg_stride = dst->shared->size;
+ H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t);
/*
* Copy the background buffer back into the in-place conversion
@@ -2243,7 +2287,7 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
for(xbuf = buf, xbkg = bkg, elmtno = 0; elmtno < nelmts; elmtno++) {
HDmemmove(xbuf, xbkg, dst->shared->size);
xbuf += buf_stride ? buf_stride : dst->shared->size;
- xbkg += bkg_stride;
+ xbkg += bkg_delta;
} /* end for */
break;
@@ -2390,7 +2434,8 @@ H5T__conv_struct_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
if(dst_memb->size > src_memb->size)
offset += src_memb->size;
} /* end for */
- for(i = src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
+ H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
+ for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
if(src2dst[i] < 0)
continue;
src_memb = src->shared->u.compnd.memb + i;
@@ -2509,7 +2554,8 @@ H5T__conv_struct_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
* is larger than the source) and them to their final position in the
* bkg buffer.
*/
- for(i = src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
+ H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
+ for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
if(src2dst[i] < 0)
continue;
src_memb = src->shared->u.compnd.memb + i;
@@ -2605,7 +2651,7 @@ H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata)
j++;
if(j >= dst->shared->u.enumer.nmembs)
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source type is not a subset of destination type")
- priv->src2dst[i] = j;
+ priv->src2dst[i] = (int)j;
} /* end for */
/*
@@ -2634,45 +2680,44 @@ H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata)
* Because this is the optimized code, we won't fix it. It should still work in some
* situations. SLU - 2011/5/24)
*/
- if (1==src->shared->size || sizeof(short)==src->shared->size || sizeof(int)==src->shared->size) {
- for (i=0; i<src->shared->u.enumer.nmembs; i++) {
- if (1==src->shared->size) {
- n = *((signed char*)(src->shared->u.enumer.value+i));
- } else if (sizeof(short)==src->shared->size) {
- n = *((short*)(src->shared->u.enumer.value+i*src->shared->size));
- } else {
- n = *((int*)(src->shared->u.enumer.value+i*src->shared->size));
- }
- if (0==i) {
+ if(1 == src->shared->size || sizeof(short) == src->shared->size || sizeof(int) == src->shared->size) {
+ for(i = 0; i < src->shared->u.enumer.nmembs; i++) {
+ if(1 == src->shared->size)
+ n = *((signed char *)(src->shared->u.enumer.value + i));
+ else if (sizeof(short) == src->shared->size)
+ n = *((short *)(src->shared->u.enumer.value + i * src->shared->size));
+ else
+ n = *((int *)(src->shared->u.enumer.value + i * src->shared->size));
+ if(0 == i) {
domain[0] = domain[1] = n;
} else {
domain[0] = MIN(domain[0], n);
domain[1] = MAX(domain[1], n);
}
- }
+ } /* end for */
- length = (domain[1]-domain[0])+1;
- if (src->shared->u.enumer.nmembs<2 ||
- (double)length/src->shared->u.enumer.nmembs<1.2) {
+ HDassert(domain[1] >= domain[0]);
+ length = (unsigned)(domain[1] - domain[0]) + 1;
+ if(src->shared->u.enumer.nmembs < 2 ||
+ (double)length / src->shared->u.enumer.nmembs < (double)(1.2f)) {
priv->base = domain[0];
priv->length = length;
- if (NULL==(map=(int *)H5MM_malloc(length*sizeof(int))))
+ if(NULL == (map = (int *)H5MM_malloc(length * sizeof(int))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- for (i=0; i<length; i++)
+ for(i = 0; i < length; i++)
map[i] = -1; /*entry unused*/
- for (i=0; i<src->shared->u.enumer.nmembs; i++) {
- if (1==src->shared->size) {
- n = *((signed char*)(src->shared->u.enumer.value+i));
- } else if (sizeof(short)==src->shared->size) {
- n = *((short*)(src->shared->u.enumer.value+i*src->shared->size));
- } else {
- n = *((int*)(src->shared->u.enumer.value+i*src->shared->size));
- }
+ for(i = 0; i < src->shared->u.enumer.nmembs; i++) {
+ if(1 == src->shared->size)
+ n = *((signed char *)(src->shared->u.enumer.value + i));
+ else if(sizeof(short) == src->shared->size)
+ n = *((short *)(src->shared->u.enumer.value + i * src->shared->size));
+ else
+ n = *((int *)(src->shared->u.enumer.value + i * src->shared->size));
n -= priv->base;
- assert(n>=0 && n<priv->length);
- assert(map[n]<0);
+ HDassert(n >= 0 && (unsigned)n < priv->length);
+ HDassert(map[n] < 0);
map[n] = priv->src2dst[i];
- }
+ } /* end for */
/*
* Replace original src2dst array with our new one. The original
@@ -2718,9 +2763,8 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
{
uint8_t *buf = (uint8_t*)_buf; /*cast for pointer arithmetic */
H5T_t *src = NULL, *dst = NULL; /*src and dst datatypes */
- H5T_t *src_super = NULL, *dst_super = NULL; /*parent types for src and dst*/
uint8_t *s = NULL, *d = NULL; /*src and dst BUF pointers */
- int src_delta, dst_delta; /*conversion strides */
+ ssize_t src_delta, dst_delta; /*conversion strides */
int n; /*src value cast as native int */
H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv);
H5P_genplist_t *plist; /*property list pointer */
@@ -2785,17 +2829,20 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* Direction of conversion.
*/
if(buf_stride) {
- src_delta = dst_delta = (int)buf_stride;
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ src_delta = dst_delta = (ssize_t)buf_stride;
s = d = buf;
} else if(dst->shared->size <= src->shared->size) {
- src_delta = (int)src->shared->size; /*overflow shouldn't be possible*/
- dst_delta = (int)dst->shared->size; /*overflow shouldn't be possible*/
+ H5_ASSIGN_OVERFLOW(src_delta, src->shared->size, size_t, ssize_t);
+ H5_ASSIGN_OVERFLOW(dst_delta, dst->shared->size, size_t, ssize_t);
s = d = buf;
} else {
- src_delta = -(int)src->shared->size; /*overflow shouldn't be possible*/
- dst_delta = -(int)dst->shared->size; /*overflow shouldn't be possible*/
- s = buf + (nelmts-1) * src->shared->size;
- d = buf + (nelmts-1) * dst->shared->size;
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
+ src_delta = -(ssize_t)src->shared->size;
+ dst_delta = -(ssize_t)dst->shared->size;
+ s = buf + (nelmts - 1) * src->shared->size;
+ d = buf + (nelmts - 1) * dst->shared->size;
}
/* Get the plist structure */
@@ -2822,28 +2869,29 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
else
n = *((int*)s);
n -= priv->base;
- if(n < 0 || n >= priv->length || priv->src2dst[n] < 0) {
+ if(n < 0 || (unsigned)n >= priv->length || priv->src2dst[n] < 0) {
/*overflow*/
except_ret = H5T_CONV_UNHANDLED;
- if(cb_struct.func) { /*If user's exception handler is present, use it*/
+ /*If user's exception handler is present, use it*/
+ if(cb_struct.func)
except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
s, d, cb_struct.user_data);
- }
- if(except_ret == H5T_CONV_UNHANDLED) {
+ if(except_ret == H5T_CONV_UNHANDLED)
HDmemset(d, 0xff, dst->shared->size);
- } else if(except_ret == H5T_CONV_ABORT)
+ else if(except_ret == H5T_CONV_ABORT)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
- } else {
+ } else
HDmemcpy(d,
- dst->shared->u.enumer.value+priv->src2dst[n]*dst->shared->size,
+ dst->shared->u.enumer.value + (unsigned)priv->src2dst[n] * dst->shared->size,
dst->shared->size);
- }
- } else {
+ } /* end if */
+ else {
/* Use O(log N) lookup */
- int lt = 0;
- int rt = src->shared->u.enumer.nmembs;
- int md, cmp;
+ unsigned lt = 0;
+ unsigned rt = src->shared->u.enumer.nmembs;
+ unsigned md;
+ int cmp;
while(lt < rt) {
md = (lt + rt) / 2;
@@ -2858,22 +2906,22 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
} /* end while */
if(lt >= rt) {
except_ret = H5T_CONV_UNHANDLED;
- if(cb_struct.func) { /*If user's exception handler is present, use it*/
+ /*If user's exception handler is present, use it*/
+ if(cb_struct.func)
except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
src, d, cb_struct.user_data);
- }
- if(except_ret == H5T_CONV_UNHANDLED) {
+ if(except_ret == H5T_CONV_UNHANDLED)
HDmemset(d, 0xff, dst->shared->size);
- } else if(except_ret == H5T_CONV_ABORT)
+ else if(except_ret == H5T_CONV_ABORT)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
} /* end if */
- else {
+ else
+ HDassert(priv->src2dst[md] >= 0);
HDmemcpy(d,
- dst->shared->u.enumer.value+priv->src2dst[md]*dst->shared->size,
+ dst->shared->u.enumer.value + (unsigned)priv->src2dst[md] * dst->shared->size,
dst->shared->size);
- } /* end else */
- }
+ } /* end else */
}
break;
@@ -2906,7 +2954,7 @@ done:
*/
herr_t
H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
- size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
+ size_t UNUSED buf_stride, size_t UNUSED bkg_stride, void *_buf,
void UNUSED *bkg, hid_t UNUSED dxpl_id)
{
H5T_t *src, *dst; /*src and dst datatypes */
@@ -3017,7 +3065,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
H5T_path_t *tpath = NULL; /* Type conversion path */
hbool_t noop_conv = FALSE; /* Flag to indicate a noop conversion */
hbool_t write_to_file = FALSE; /* Flag to indicate writing to file */
- hbool_t parent_is_vlen; /* Flag to indicate parent is vlen datatyp */
+ htri_t parent_is_vlen; /* Flag to indicate parent is vlen datatyp */
hid_t tsrc_id = -1, tdst_id = -1;/*temporary type atoms */
H5T_t *src = NULL; /*source datatype */
H5T_t *dst = NULL; /*destination datatype */
@@ -3028,7 +3076,6 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
ssize_t s_stride, d_stride; /*src and dst strides */
ssize_t b_stride; /*bkg stride */
size_t safe; /*how many elements are safe to process in each pass */
- ssize_t seq_len; /*the number of elements in the current sequence*/
size_t bg_seq_len = 0;
size_t src_base_size, dst_base_size;/*source & destination base size*/
void *conv_buf = NULL; /*temporary conversion buffer */
@@ -3116,12 +3163,13 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
noop_conv = TRUE;
/* Check if we need a temporary buffer for this conversion */
- parent_is_vlen = H5T_detect_class(dst->shared->parent, H5T_VLEN, FALSE);
+ if((parent_is_vlen = H5T_detect_class(dst->shared->parent, H5T_VLEN, FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_SYSTEM, FAIL, "internal error when detecting variable-length class")
if(tpath->cdata.need_bkg || parent_is_vlen) {
/* Set up initial background buffer */
tmp_buf_size = MAX(src_base_size, dst_base_size);
if(NULL == (tmp_buf = H5FL_BLK_CALLOC(vlen_seq,tmp_buf_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion")
} /* end if */
/* Get the allocation info */
@@ -3141,17 +3189,22 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
while(nelmts > 0) {
/* Check if we need to go backwards through the buffer */
if(d_stride > s_stride) {
+ /* Sanity check */
+ HDassert(s_stride > 0);
+ HDassert(d_stride > 0);
+ HDassert(b_stride >= 0);
+
/* Compute the number of "safe" destination elements at */
/* the end of the buffer (Those which don't overlap with */
/* any source elements at the beginning of the buffer) */
- safe = nelmts - (((nelmts * s_stride) + (d_stride - 1)) / d_stride);
+ safe = nelmts - (((nelmts * (size_t)s_stride) + ((size_t)d_stride - 1)) / (size_t)d_stride);
/* If we're down to the last few elements, just wrap up */
/* with a "real" reverse copy */
if(safe < 2) {
- s = (uint8_t *)buf + (nelmts - 1) * s_stride;
- d = (uint8_t *)buf + (nelmts - 1) * d_stride;
- b = (uint8_t *)bkg + (nelmts - 1) * b_stride;
+ s = (uint8_t *)buf + (nelmts - 1) * (size_t)s_stride;
+ d = (uint8_t *)buf + (nelmts - 1) * (size_t)d_stride;
+ b = (uint8_t *)bkg + (nelmts - 1) * (size_t)b_stride;
s_stride = -s_stride;
d_stride = -d_stride;
b_stride = -b_stride;
@@ -3159,9 +3212,9 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
safe = nelmts;
} /* end if */
else {
- s = (uint8_t *)buf + (nelmts - safe) * s_stride;
- d = (uint8_t *)buf + (nelmts - safe) * d_stride;
- b = (uint8_t *)bkg + (nelmts - safe) * b_stride;
+ s = (uint8_t *)buf + (nelmts - safe) * (size_t)s_stride;
+ d = (uint8_t *)buf + (nelmts - safe) * (size_t)d_stride;
+ b = (uint8_t *)bkg + (nelmts - safe) * (size_t)b_stride;
} /* end else */
} /* end if */
else {
@@ -3179,9 +3232,13 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't set VL data to 'nil'")
} /* end if */
else {
+ ssize_t sseq_len; /* (signed) The number of elements in the current sequence*/
+ size_t seq_len; /* The number of elements in the current sequence*/
+
/* Get length of element sequences */
- if((seq_len = (*(src->shared->u.vlen.getlen))(s)) < 0)
+ if((sseq_len = (*(src->shared->u.vlen.getlen))(s)) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect length")
+ seq_len = (size_t)sseq_len;
/* If we are reading from memory and there is no conversion, just get the pointer to sequence */
if(write_to_file && noop_conv) {
@@ -3230,7 +3287,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/* If we are writing and there is a nested VL type, read
* the sequence into the background buffer */
if(nested) {
- uint8_t *tmp = b;
+ const uint8_t *tmp = b;
UINT32DECODE(tmp, bg_seq_len);
if(bg_seq_len > 0) {
@@ -3240,40 +3297,40 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
HDmemset(tmp_buf, 0, tmp_buf_size);
} /* end if */
- H5F_addr_decode(dst->shared->u.vlen.f, (const uint8_t **)&tmp, &(bg_hobjid.addr));
- INT32DECODE(tmp, bg_hobjid.idx);
+ H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(bg_hobjid.addr));
+ UINT32DECODE(tmp, bg_hobjid.idx);
if(NULL == H5HG_read(dst->shared->u.vlen.f, dxpl_id, &bg_hobjid, tmp_buf, NULL))
HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL sequence into background buffer")
} /* end if */
/* If the sequence gets shorter, pad out the original sequence with zeros */
- if((ssize_t)bg_seq_len < seq_len)
+ if(bg_seq_len < seq_len)
HDmemset((uint8_t *)tmp_buf + dst_base_size * bg_seq_len, 0, (seq_len - bg_seq_len) * dst_base_size);
} /* end if */
/* Convert VL sequence */
- if(H5T_convert(tpath, tsrc_id, tdst_id, (size_t)seq_len, (size_t)0, (size_t)0, conv_buf, tmp_buf, dxpl_id) < 0)
+ if(H5T_convert(tpath, tsrc_id, tdst_id, seq_len, (size_t)0, (size_t)0, conv_buf, tmp_buf, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
} /* end if */
/* Write sequence to destination location */
- if((*(dst->shared->u.vlen.write))(dst->shared->u.vlen.f, dxpl_id, vl_alloc_info, d, conv_buf, b, (size_t)seq_len, dst_base_size) < 0)
+ if((*(dst->shared->u.vlen.write))(dst->shared->u.vlen.f, dxpl_id, vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write VL data")
if(!noop_conv) {
/* For nested VL case, free leftover heap objects from the deeper level if the length of new data elements is shorter than the old data elements.*/
- if(nested && seq_len < (ssize_t)bg_seq_len) {
+ if(nested && seq_len < bg_seq_len) {
size_t parent_seq_len;
- uint8_t *tmp_p;
+ const uint8_t *tmp;
size_t u;
/* TMP_P is reset each time in the loop because DST_BASE_SIZE may include some data in addition to VL info. - SLU */
for(u = seq_len; u < bg_seq_len; u++) {
- tmp_p = (uint8_t*)tmp_buf + u * dst_base_size;
- UINT32DECODE(tmp_p, parent_seq_len);
+ tmp = (uint8_t *)tmp_buf + u * dst_base_size;
+ UINT32DECODE(tmp, parent_seq_len);
if(parent_seq_len > 0) {
- H5F_addr_decode(dst->shared->u.vlen.f, (const uint8_t **)&tmp_p, &(parent_hobjid.addr));
- INT32DECODE(tmp_p, parent_hobjid.idx);
+ H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(parent_hobjid.addr));
+ UINT32DECODE(tmp, parent_hobjid.idx);
if(H5HG_remove(dst->shared->u.vlen.f, dxpl_id, &parent_hobjid) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object")
} /* end if */
@@ -3343,7 +3400,7 @@ H5T__conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
H5T_t *src = NULL; /*source datatype */
H5T_t *dst = NULL; /*destination datatype */
uint8_t *sp, *dp; /*source and dest traversal ptrs */
- size_t src_delta, dst_delta; /*source & destination stride */
+ ssize_t src_delta, dst_delta; /*source & destination stride */
int direction; /*direction of traversal */
size_t elmtno; /*element number counter */
unsigned u; /* local index variable */
@@ -3408,8 +3465,11 @@ H5T__conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/*
* Direction & size of buffer traversal.
*/
- src_delta = direction * (buf_stride ? buf_stride : src->shared->size);
- dst_delta = direction * (buf_stride ? buf_stride : dst->shared->size);
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
+ src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
+ dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
/* Set up conversion path for base elements */
if(NULL == (tpath = H5T_path_find(src->shared->parent, dst->shared->parent, NULL, NULL, dxpl_id, FALSE))) {
@@ -3499,6 +3559,7 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
{
H5T_t *src = NULL; /*source datatype */
H5T_t *dst = NULL; /*destination datatype */
+ ssize_t src_delta, dst_delta; /*source & destination stride */
int direction; /*direction of traversal */
size_t elmtno; /*element number */
size_t half_size; /*half the type size */
@@ -3563,6 +3624,15 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
direction = -1;
}
+ /*
+ * Direction & size of buffer traversal.
+ */
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
+ src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
+ dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
+
/* Get the plist structure */
if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
@@ -3575,18 +3645,18 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
src_rev = (uint8_t*)H5MM_calloc(src->shared->size);
/* The conversion loop */
- for (elmtno=0; elmtno<nelmts; elmtno++) {
+ for(elmtno = 0; elmtno < nelmts; elmtno++) {
/*
* If the source and destination buffers overlap then use a
* temporary buffer for the destination.
*/
- if (direction>0) {
+ if(direction > 0) {
s = sp;
- d = elmtno<olap ? dbuf : dp;
+ d = elmtno < olap ? dbuf : dp;
} else {
s = sp;
- d = elmtno+olap >= nelmts ? dbuf : dp;
+ d = elmtno + olap >= nelmts ? dbuf : dp;
}
#ifndef NDEBUG
/* I don't quite trust the overlap calculations yet --rpm */
@@ -3844,16 +3914,13 @@ H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* If we had used a temporary buffer for the destination then we
* should copy the value to the true destination buffer.
*/
- if (d==dbuf)
- HDmemcpy (dp, d, dst->shared->size);
- if (buf_stride) {
- sp += direction * buf_stride;
- dp += direction * buf_stride;
- } else {
- sp += direction * src->shared->size;
- dp += direction * dst->shared->size;
- }
- }
+ if(d==dbuf)
+ HDmemcpy(dp, d, dst->shared->size);
+
+ /* Advance source & destination pointers by delta amounts */
+ sp += src_delta;
+ dp += dst_delta;
+ } /* end for */
break;
@@ -3909,6 +3976,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
H5T_t *dst_p; /*destination datatype */
H5T_atomic_t src; /*atomic source info */
H5T_atomic_t dst; /*atomic destination info */
+ ssize_t src_delta, dst_delta; /*source & destination stride */
int direction; /*forward or backward traversal */
size_t elmtno; /*element number */
size_t half_size; /*half the type size */
@@ -3921,11 +3989,11 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
uint8_t tmp1, tmp2; /*temp variables for swapping bytes*/
/* Conversion-related variables */
- hssize_t expo; /*exponent */
+ int64_t expo; /*exponent */
hssize_t expo_max; /*maximum possible dst exponent */
size_t msize = 0; /*useful size of mantissa in src*/
size_t mpos; /*offset to useful mant is src */
- hssize_t sign; /*source sign bit value */
+ uint64_t sign; /*source sign bit value */
size_t mrsh; /*amount to right shift mantissa*/
hbool_t carry = 0; /*carry after rounding mantissa */
size_t i; /*miscellaneous counters */
@@ -3991,6 +4059,15 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
direction = -1;
}
+ /*
+ * Direction & size of buffer traversal.
+ */
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(src_p->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst_p->shared->size, size_t, ssize_t);
+ src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src_p->shared->size);
+ dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst_p->shared->size);
+
/* Get the plist structure */
if(NULL == (plist = H5P_object_verify(dxpl_id,H5P_DATASET_XFER)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
@@ -4142,9 +4219,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
goto padding;
-#ifdef H5_VMS
- } /*Temporary solution to handle VAX special values*/
-#else /*H5_VMS*/
+#ifndef H5_VMS /*Temporary solution to handle VAX special values*/
} else if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
H5T_BIT_LSB, FALSE)<0) {
/* NaN */
@@ -4169,15 +4244,15 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
goto padding;
- }
#endif /*H5_VMS*/
+ }
/*
* Get the exponent as an unsigned quantity from the section of
* the source bit field where it's located. Don't worry about
* the exponent bias yet.
*/
- expo = H5T__bit_get_d(s, src.u.f.epos, src.u.f.esize);
+ expo = (int64_t)H5T__bit_get_d(s, src.u.f.epos, src.u.f.esize);
if(expo==0)
denormalized=TRUE;
@@ -4189,10 +4264,9 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
implied = 1;
mpos = src.u.f.mpos;
mrsh = 0;
- if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
- if ((bitno=H5T__bit_find(s, src.u.f.mpos, src.u.f.msize,
- H5T_BIT_MSB, TRUE))>0) {
- msize = bitno;
+ if(0 == expo || H5T_NORM_NONE == src.u.f.norm) {
+ if((bitno = H5T__bit_find(s, src.u.f.mpos, src.u.f.msize, H5T_BIT_MSB, TRUE)) > 0) {
+ msize = (size_t)bitno;
} else if (0==bitno) {
msize = 1;
H5T__bit_set(s, src.u.f.mpos, (size_t)1, FALSE);
@@ -4200,8 +4274,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
} else if (H5T_NORM_IMPLIED==src.u.f.norm) {
msize = src.u.f.msize;
} else {
- assert("normalization method not implemented yet" && 0);
- HDabort();
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
}
/*
@@ -4215,13 +4288,12 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* the source exponent bias.
*/
if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
- assert(bitno>=0);
- expo -= (src.u.f.ebias-1) + (src.u.f.msize-bitno);
+ HDassert(bitno>=0);
+ expo -= (int64_t)((src.u.f.ebias - 1) + (src.u.f.msize - (size_t)bitno));
} else if (H5T_NORM_IMPLIED==src.u.f.norm) {
- expo -= src.u.f.ebias;
+ expo -= (int64_t)src.u.f.ebias;
} else {
- assert("normalization method not implemented yet" && 0);
- HDabort();
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
}
/*
@@ -4236,7 +4308,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* bias and clipping by the minimum and maximum possible
* destination exponent values.
*/
- expo += dst.u.f.ebias;
+ expo += (int64_t)dst.u.f.ebias;
if (expo < -(hssize_t)(dst.u.f.msize)) {
/* The exponent is way too small. Result is zero. */
@@ -4250,7 +4322,7 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* accomodate that value. The mantissa of course is no
* longer normalized.
*/
- H5_ASSIGN_OVERFLOW(mrsh,(mrsh+1-expo),hssize_t,size_t);
+ mrsh += (size_t)(1 - expo);
expo = 0;
denormalized=TRUE;
} else if (expo>=expo_max) {
@@ -4289,20 +4361,20 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* mantissa bit is `1', else it is `10' binary.
*/
if (msize>0 && mrsh<=dst.u.f.msize && mrsh+msize>dst.u.f.msize) {
- bitno = (ssize_t)(mrsh+msize - dst.u.f.msize);
- assert(bitno>=0 && (size_t)bitno<=msize);
- /*If the 1st bit being cut off is set and source isn't denormalized.*/
- if(H5T__bit_get_d(s, (mpos + bitno) - 1, (size_t)1) && !denormalized) {
- /*Don't do rounding if exponent is 111...110 and mantissa is 111...11.
- *To do rounding and increment exponent in this case will create an infinity value.*/
- if((H5T__bit_find(s, mpos+bitno, msize-bitno, H5T_BIT_LSB, FALSE)>=0 || expo<expo_max-1)) {
- carry = H5T__bit_inc(s, mpos+bitno-1, 1+msize-bitno);
- if (carry)
+ bitno = (ssize_t)(mrsh + msize - dst.u.f.msize);
+ HDassert(bitno >= 0 && (size_t)bitno <= msize);
+ /* If the 1st bit being cut off is set and source isn't denormalized.*/
+ if(H5T__bit_get_d(s, (mpos + (size_t)bitno) - 1, (size_t)1) && !denormalized) {
+ /* Don't do rounding if exponent is 111...110 and mantissa is 111...11.
+ * To do rounding and increment exponent in this case will create an infinity value.*/
+ if((H5T__bit_find(s, mpos + (size_t)bitno, msize - (size_t)bitno, H5T_BIT_LSB, FALSE) >= 0 || expo < expo_max - 1)) {
+ carry = (hbool_t)H5T__bit_inc(s, mpos + (size_t)bitno - 1, 1 + msize - (size_t)bitno);
+ if(carry)
implied = 2;
}
- } else if(H5T__bit_get_d(s, (mpos + bitno) - 1, (size_t)1) && denormalized)
- /*For either source or destination, denormalized value doesn't increment carry.*/
- H5T__bit_inc(s, mpos+bitno-1, 1+msize-bitno);
+ } else if(H5T__bit_get_d(s, (mpos + (size_t)bitno) - 1, (size_t)1) && denormalized)
+ /* For either source or destination, denormalized value doesn't increment carry.*/
+ H5T__bit_inc(s, mpos + (size_t)bitno - 1, 1 + msize - (size_t)bitno);
}
else
carry=0;
@@ -4420,15 +4492,12 @@ H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* should copy the value to the true destination buffer.
*/
next:
- if (d==dbuf)
- HDmemcpy (dp, d, dst_p->shared->size);
- if (buf_stride) {
- sp += direction * buf_stride;
- dp += direction * buf_stride;
- } else {
- sp += direction * src_p->shared->size;
- dp += direction * dst_p->shared->size;
- }
+ if(d == dbuf)
+ HDmemcpy(dp, d, dst_p->shared->size);
+
+ /* Advance source & destination pointers by delta amounts */
+ sp += src_delta;
+ dp += dst_delta;
}
break;
@@ -4474,7 +4543,8 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
{
H5T_t *src=NULL; /*source datatype */
H5T_t *dst=NULL; /*destination datatype */
- int direction; /*direction of traversal */
+ ssize_t src_delta, dst_delta; /*source & destination stride */
+ int direction; /*direction of traversal */
size_t elmtno; /*element number */
size_t olap; /*num overlapping elements */
size_t nchars=0; /*number of characters copied */
@@ -4499,8 +4569,8 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
if((H5T_CSET_ASCII == src->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 == dst->shared->u.atomic.u.s.cset)
|| (H5T_CSET_ASCII == dst->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 == src->shared->u.atomic.u.s.cset))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "The library doesn't convert between strings of ASCII and UTF")
- if(src->shared->u.atomic.u.s.pad < 0 || src->shared->u.atomic.u.s.pad >= H5T_NPAD ||
- dst->shared->u.atomic.u.s.pad < 0 || dst->shared->u.atomic.u.s.pad >= H5T_NPAD)
+ if(src->shared->u.atomic.u.s.pad < 0 || src->shared->u.atomic.u.s.pad >= H5T_NSTR ||
+ dst->shared->u.atomic.u.s.pad < 0 || dst->shared->u.atomic.u.s.pad >= H5T_NSTR)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad character padding")
cdata->need_bkg = H5T_BKG_NO;
break;
@@ -4541,6 +4611,15 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
direction = -1;
}
+ /*
+ * Direction & size of buffer traversal.
+ */
+ H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
+ H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
+ src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
+ dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
+
/* Allocate the overlap buffer */
if(NULL == (dbuf = (uint8_t *)H5MM_malloc(dst->shared->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for string conversion")
@@ -4613,6 +4692,7 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
case H5T_STR_RESERVED_14:
case H5T_STR_RESERVED_15:
case H5T_STR_ERROR:
+ default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source string padding method not supported")
} /* end switch */
@@ -4648,6 +4728,7 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
case H5T_STR_RESERVED_14:
case H5T_STR_RESERVED_15:
case H5T_STR_ERROR:
+ default:
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination string padding method not supported")
} /* end switch */
@@ -4655,15 +4736,12 @@ H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
* If we used a temporary buffer for the destination then we
* should copy the value to the true destination buffer.
*/
- if (d==dbuf)
+ if(d == dbuf)
HDmemcpy(dp, d, dst->shared->size);
- if (buf_stride) {
- sp += direction * buf_stride;
- dp += direction * buf_stride;
- } else {
- sp += direction * src->shared->size;
- dp += direction * dst->shared->size;
- }
+
+ /* Advance source & destination pointers by delta amounts */
+ sp += src_delta;
+ dp += dst_delta;
} /* end for */
break;
@@ -9044,8 +9122,7 @@ H5T__conv_f_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
} else if (H5T_NORM_IMPLIED==src.u.f.norm) {
expo -= src.u.f.ebias;
} else {
- assert("normalization method not implemented yet" && 0);
- HDabort();
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
}
/*
@@ -9548,8 +9625,7 @@ H5T__conv_i_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
if (H5T_NORM_NONE==dst.u.f.norm || H5T_NORM_IMPLIED==dst.u.f.norm) {
expo = first + dst.u.f.ebias;
} else {
- assert("normalization method not implemented yet" && 0);
- HDabort();
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
}
/* Handle mantissa part here */
@@ -9629,7 +9705,7 @@ H5T__conv_i_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/* Check if the exponent is too big */
- expo_max = (hsize_t)HDpow((double)2.0, (double)dst.u.f.esize) - 1;
+ expo_max = (hsize_t)HDpow((double)2.0f, (double)dst.u.f.esize) - 1;
if(expo > expo_max) { /*overflows*/
if(cb_struct.func) { /*user's exception handler. Reverse back source order*/
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c
index f497d1e..52a2cde 100644
--- a/src/H5Tvlen.c
+++ b/src/H5Tvlen.c
@@ -882,7 +882,7 @@ H5T_vlen_disk_read(H5F_t *f, hid_t dxpl_id, void *_vl, void *buf, size_t UNUSED
/* Get the heap information */
H5F_addr_decode(f,(const uint8_t **)&vl,&(hobjid.addr));
- INT32DECODE(vl,hobjid.idx);
+ UINT32DECODE(vl,hobjid.idx);
/* Check if this sequence actually has any data */
if(hobjid.addr>0) {
@@ -935,7 +935,7 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED
/* Get heap information */
H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr));
- INT32DECODE(bg, bg_hobjid.idx);
+ UINT32DECODE(bg, bg_hobjid.idx);
/* Free heap object for old data */
if(bg_hobjid.addr > 0) {
@@ -955,7 +955,7 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED
/* Encode the heap information */
H5F_addr_encode(f, &vl, hobjid.addr);
- INT32ENCODE(vl, hobjid.idx);
+ UINT32ENCODE(vl, hobjid.idx);
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -997,7 +997,7 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg)
/* Get heap information */
H5F_addr_decode(f, (const uint8_t **)&bg, &(bg_hobjid.addr));
- INT32DECODE(bg, bg_hobjid.idx);
+ UINT32DECODE(bg, bg_hobjid.idx);
/* Free heap object for old data */
if(bg_hobjid.addr > 0) {
@@ -1012,7 +1012,7 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg)
/* Encode the "nil" heap pointer information */
H5F_addr_encode(f, &vl, (haddr_t)0);
- INT32ENCODE(vl, 0);
+ UINT32ENCODE(vl, 0);
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5private.h b/src/H5private.h
index 78d3d9d..731a7f6 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -2345,7 +2345,11 @@ func_init_failed: \
#define H5_GLUE4(w,x,y,z) w##x##y##z
/* Compile-time "assert" macro */
-#define HDcompile_assert(e) do { enum { compile_assert__ = 1 / (e) }; } while(0)
+#define HDcompile_assert(e) ((void)sizeof(char[ !!(e) ? 1 : -1]))
+/* Variants that are correct, but generate compile-time warnings in some circumstances:
+ #define HDcompile_assert(e) do { enum { compile_assert__ = 1 / (e) }; } while(0)
+ #define HDcompile_assert(e) do { typedef struct { unsigned int b: (e); } x; } while(0)
+*/
/* Private functions, not part of the publicly documented API */
H5_DLL herr_t H5_init_library(void);
diff --git a/test/H5srcdir.h b/test/H5srcdir.h
index 8bc8780..202d050 100644
--- a/test/H5srcdir.h
+++ b/test/H5srcdir.h
@@ -50,10 +50,12 @@ static const char *H5_get_srcdir_filename(const char *filename)
#ifdef H5_VMS
if(filename[0] == '[') {
char *tmp = filename;
- srcdir_testpath[strlen(srcdir)-1] = '\0';
- strcat(srcdir_testpath, ++tmp);
- } else
- strcat(srcdir_testpath, filename);
+
+ srcdir_testpath[HDstrlen(srcdir) - 1] = '\0';
+ HDstrcat(srcdir_testpath, ++tmp);
+ } /* end if */
+ else
+ HDstrcat(srcdir_testpath, filename);
#else
HDstrcat(srcdir_testpath, "/");
HDstrcat(srcdir_testpath, filename);
@@ -84,4 +86,3 @@ static const char *H5_get_srcdir(void)
}
#endif /* _H5SRCDIR_H */
-
diff --git a/test/h5test.c b/test/h5test.c
index 91497e3..32d78bd 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -1124,24 +1124,8 @@ h5_make_local_copy(const char *origfilename, const char *local_copy_name)
{
int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */
ssize_t nread; /* Number of bytes read in */
- char buf[READ_BUF_SIZE]; /* Buffer for copying data */
- char filename[FILENAME_BUF_SIZE] = "";
-#ifdef H5_VMS
- HDstrcat(filename, origfilename);
-#else
- const char * srcdir = HDgetenv("srcdir"); /* The source directory */
-
- /* Check for using the srcdir from configure time */
- if(NULL == srcdir)
- srcdir = config_srcdir;
-
- if(srcdir && ((HDstrlen(srcdir) +
- HDstrlen(origfilename) + 6) < FILENAME_BUF_SIZE)) {
- HDstrcpy(filename, srcdir);
- HDstrcat(filename, "/");
- }
- HDstrcat(filename, origfilename);
-#endif
+ char buf[READ_BUF_SIZE]; /* Buffer for copying data */
+ const char *filename = H5_get_srcdir_filename(origfilename);; /* Get the test file name to copy */
/* Copy old file into temporary file */
if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1;
diff --git a/tools/h5jam/getub.c b/tools/h5jam/getub.c
index f536605..d84f7f2 100644
--- a/tools/h5jam/getub.c
+++ b/tools/h5jam/getub.c
@@ -153,7 +153,7 @@ main (int argc, const char *argv[])
exit (EXIT_FAILURE);
}
- buf = malloc ((unsigned)(size + 1));
+ buf = (char *)HDmalloc ((unsigned)(size + 1));
if (buf == NULL)
{
HDclose (fd);
diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c
index a68760d..dcc2c08 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -136,7 +136,8 @@ static int display_object = FALSE; /* not implemented yet */
/* a structure for handling the order command-line parameters come in */
struct handler_t {
- char *obj;
+ size_t obj_count;
+ char **obj;
};
@@ -552,7 +553,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
if(type_found)
(iter->dset_type_info[u].count)++;
else {
- unsigned curr_ntype = iter->dset_ntypes;
+ unsigned curr_ntype = (unsigned)iter->dset_ntypes;
/* Increment # of datatypes seen for datasets */
iter->dset_ntypes++;
@@ -670,9 +671,11 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
break;
case H5O_TYPE_NAMED_DATATYPE:
- datatype_stats(iter, oi);
+ datatype_stats(iter, oi);
break;
+ case H5O_TYPE_UNKNOWN:
+ case H5O_TYPE_NTYPES:
default:
/* Gather statistics about this type of object */
iter->uniq_others++;
@@ -710,6 +713,9 @@ lnk_stats(const char UNUSED *path, const H5L_info_t *li, void *_iter)
iter->uniq_links++;
break;
+ case H5L_TYPE_HARD:
+ case H5L_TYPE_MAX:
+ case H5L_TYPE_ERROR:
default:
/* Gather statistics about this type of object */
iter->uniq_others++;
@@ -740,19 +746,19 @@ freespace_stats(hid_t fid, iter_t *iter)
/* Query section information */
if((nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, 0, NULL)) < 0)
- return(FAIL);
+ return(FAIL);
else if(nsects) {
- if(NULL == (sect_info = (H5F_sect_info_t *)HDcalloc((size_t)nsects, sizeof(H5F_sect_info_t))))
- return(FAIL);
- nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info);
- HDassert(nsects);
+ if(NULL == (sect_info = (H5F_sect_info_t *)HDcalloc((size_t)nsects, sizeof(H5F_sect_info_t))))
+ return(FAIL);
+ nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info);
+ HDassert(nsects);
} /* end else-if */
for(u = 0; u < (size_t)nsects; u++) {
unsigned bin; /* "bin" the number of objects falls in */
- if(sect_info[u].size < SIZE_SMALL_SECTS)
- (iter->num_small_sects[(size_t)sect_info[u].size])++;
+ if(sect_info[u].size < SIZE_SMALL_SECTS)
+ (iter->num_small_sects[(size_t)sect_info[u].size])++;
/* Add section size to proper bin */
bin = ceil_log10((unsigned long)sect_info[u].size);
@@ -781,6 +787,35 @@ freespace_stats(hid_t fid, iter_t *iter)
/*-------------------------------------------------------------------------
+ * Function: hand_free
+ *
+ * Purpose: Free handler structure
+ *
+ * Return: Success: 0
+ *
+ * Failure: Never fails
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+hand_free(struct handler_t *hand)
+{
+ if(hand) {
+ unsigned u;
+
+ for(u = 0; u < hand->obj_count; u++)
+ if(hand->obj[u]) {
+ HDfree(hand->obj[u]);
+ hand->obj[u] = NULL;
+ } /* end if */
+ hand->obj_count = 0;
+ HDfree(hand->obj);
+ HDfree(hand);
+ } /* end if */
+} /* end hand_free() */
+
+
+/*-------------------------------------------------------------------------
* Function: parse_command_line
*
* Purpose: Parses command line and sets up global variable to control output
@@ -794,50 +829,25 @@ freespace_stats(hid_t fid, iter_t *iter)
*
*-------------------------------------------------------------------------
*/
-static struct handler_t *
-parse_command_line(int argc, const char *argv[])
+static int
+parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret)
{
- int opt, i;
+ int opt;
+ unsigned u;
struct handler_t *hand = NULL;
- /* Allocate space to hold the command line info */
- if((hand = (struct handler_t *)HDcalloc((size_t)argc, sizeof(struct handler_t)))==NULL) {
- error_msg("unable to parse command line arguments \n");
- goto error;
- }
-
/* parse command line options */
- while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
- switch ((char)opt) {
+ while((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
+ switch((char)opt) {
case 'h':
usage(h5tools_getprogname());
h5tools_setstatus(EXIT_SUCCESS);
- if (hand) {
- for (i = 0; i < argc; i++)
- if(hand[i].obj) {
- free(hand[i].obj);
- hand[i].obj=NULL;
- }
-
- free(hand);
- hand = NULL;
- }
goto done;
break;
case 'V':
print_version(h5tools_getprogname());
h5tools_setstatus(EXIT_SUCCESS);
- if (hand) {
- for (i = 0; i < argc; i++)
- if(hand[i].obj) {
- free(hand[i].obj);
- hand[i].obj=NULL;
- }
-
- free(hand);
- hand = NULL;
- }
goto done;
break;
@@ -894,45 +904,52 @@ parse_command_line(int argc, const char *argv[])
case 'O':
display_all = FALSE;
display_object = TRUE;
- for(i = 0; i < argc; i++)
- if(!hand[i].obj) {
- hand[i].obj = HDstrdup(opt_arg);
- break;
+
+ /* Allocate space to hold the command line info */
+ if(NULL == (hand = (struct handler_t *)HDcalloc((size_t)1, sizeof(struct handler_t)))) {
+ error_msg("unable to allocate memory for object struct\n");
+ goto error;
+ } /* end if */
+
+ /* Allocate space to hold the object strings */
+ hand->obj_count = (size_t)argc;
+ if(NULL == (hand->obj = (char **)HDcalloc((size_t)argc, sizeof(char *)))) {
+ error_msg("unable to allocate memory for object array\n");
+ goto error;
+ } /* end if */
+
+ /* Store object names */
+ for(u = 0; u < hand->obj_count; u++)
+ if(NULL == (hand->obj[u] = HDstrdup(opt_arg))) {
+ error_msg("unable to allocate memory for object name\n");
+ goto error;
} /* end if */
break;
default:
usage(h5tools_getprogname());
- h5tools_setstatus(EXIT_FAILURE);
goto error;
} /* end switch */
} /* end while */
/* check for file name to be processed */
- if (argc <= opt_ind) {
+ if(argc <= opt_ind) {
error_msg("missing file name\n");
usage(h5tools_getprogname());
- h5tools_setstatus(EXIT_FAILURE);
goto error;
} /* end if */
+ /* Set handler structure */
+ *hand_ret = hand;
+
done:
- return hand;
+ return 0;
error:
- if (hand) {
- for (i = 0; i < argc; i++)
- if(hand[i].obj) {
- free(hand[i].obj);
- hand[i].obj=NULL;
- }
-
- free(hand);
- hand = NULL;
- }
+ hand_free(hand);
h5tools_setstatus(EXIT_FAILURE);
- return hand;
+ return -1;
}
@@ -947,32 +964,39 @@ error:
*
*-------------------------------------------------------------------------
*/
-static herr_t
+static void
iter_free(iter_t *iter)
{
/* Clear array of bins for group counts */
- if(iter->group_bins)
- free(iter->group_bins);
- iter->group_bins = NULL;
+ if(iter->group_bins) {
+ HDfree(iter->group_bins);
+ iter->group_bins = NULL;
+ } /* end if */
+
/* Clear array of bins for attribute counts */
- if(iter->attr_bins)
- free(iter->attr_bins);
- iter->attr_bins = NULL;
+ if(iter->attr_bins) {
+ HDfree(iter->attr_bins);
+ iter->attr_bins = NULL;
+ } /* end if */
+
/* Clear dataset datatype information found */
- if(iter->dset_type_info)
- free(iter->dset_type_info);
- iter->dset_type_info = NULL;
+ if(iter->dset_type_info) {
+ HDfree(iter->dset_type_info);
+ iter->dset_type_info = NULL;
+ } /* end if */
+
/* Clear array of bins for dataset dimensions */
- if(iter->dset_dim_bins)
- free(iter->dset_dim_bins);
- iter->dset_dim_bins = NULL;
- /* Clear array of bins for free-space section sizes */
- if(iter->sect_bins)
- free(iter->sect_bins);
- iter->sect_bins = NULL;
+ if(iter->dset_dim_bins) {
+ HDfree(iter->dset_dim_bins);
+ iter->dset_dim_bins = NULL;
+ } /* end if */
- return 0;
-}
+ /* Clear array of bins for free-space section sizes */
+ if(iter->sect_bins) {
+ HDfree(iter->sect_bins);
+ iter->sect_bins = NULL;
+ } /* end if */
+} /* end iter_free() */
/*-------------------------------------------------------------------------
@@ -1428,7 +1452,7 @@ print_storage_summary(const iter_t *iter)
{
hsize_t total_meta = 0;
hsize_t unaccount = 0;
- float percent = 0.0;
+ double percent = 0.0f;
HDfprintf(stdout, "File space management strategy: %s\n", FS_STRATEGY_NAME[iter->fs_strategy]);
printf("Summary of file space information:\n");
@@ -1451,7 +1475,7 @@ print_storage_summary(const iter_t *iter)
HDfprintf(stdout, " File metadata: %Hu bytes\n", total_meta);
HDfprintf(stdout, " Raw data: %Hu bytes\n", iter->dset_storage_size);
- percent = ((float)iter->free_space / (float)iter->filesize) * 100;
+ percent = ((double)iter->free_space / (double)iter->filesize) * (double)100.0f;
HDfprintf(stdout, " Amount/Percent of tracked free space: %Hu bytes/%3.1f%\n",
iter->free_space, percent);
@@ -1584,10 +1608,7 @@ main(int argc, const char *argv[])
iter_t iter;
const char *fname = NULL;
hid_t fid = -1;
- hid_t fcpl;
struct handler_t *hand = NULL;
- H5F_info2_t finfo;
- int i;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
@@ -1598,97 +1619,91 @@ main(int argc, const char *argv[])
/* Initialize h5tools lib */
h5tools_init();
- if((hand = parse_command_line(argc, argv))==NULL) {
- goto done;
- }
-
- fname = argv[opt_ind];
-
- printf("Filename: %s\n", fname);
-
HDmemset(&iter, 0, sizeof(iter));
- fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
- if(fid < 0) {
- error_msg("unable to open file \"%s\"\n", fname);
- h5tools_setstatus(EXIT_FAILURE);
+ if(parse_command_line(argc, argv, &hand) < 0)
goto done;
- } /* end if */
- /* Initialize iter structure */
- iter.fid = fid;
-
- if(H5Fget_filesize(fid, &iter.filesize) < 0)
- warn_msg("Unable to retrieve file size\n");
- HDassert(iter.filesize != 0);
-
- /* Get storge info for file-level structures */
- if(H5Fget_info2(fid, &finfo) < 0)
- warn_msg("Unable to retrieve file info\n");
- else {
- iter.super_size = finfo.super.super_size;
- iter.super_ext_size = finfo.super.super_ext_size;
- iter.SM_hdr_storage_size = finfo.sohm.hdr_size;
- iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size;
- iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size;
- iter.free_space = finfo.free.tot_space;
- iter.free_hdr = finfo.free.meta_size;
- } /* end else */
-
- if((fcpl = H5Fget_create_plist(fid)) < 0)
- warn_msg("Unable to retrieve file creation property\n");
-
- if(H5Pget_userblock(fcpl, &iter.ublk_size) < 0)
- warn_msg("Unable to retrieve userblock size\n");
+ fname = argv[opt_ind];
- if(H5Pget_file_space(fcpl, &iter.fs_strategy, &iter.fs_threshold) < 0)
- warn_msg("Unable to retrieve file space information\n");
- HDassert(iter.fs_strategy != 0 && iter.fs_strategy < H5F_FILE_SPACE_NTYPES);
+ /* Check for filename given */
+ if(fname) {
+ hid_t fcpl;
+ H5F_info2_t finfo;
- /* get information for free-space sections */
- if(freespace_stats(fid, &iter) < 0)
- warn_msg("Unable to retrieve freespace info\n");
+ printf("Filename: %s\n", fname);
- /* Walk the objects or all file */
- if(display_object) {
- unsigned u;
+ fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
+ if(fid < 0) {
+ error_msg("unable to open file \"%s\"\n", fname);
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ } /* end if */
- u = 0;
- while(hand[u].obj) {
- if (h5trav_visit(fid, hand[u].obj, TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
- warn_msg("Unable to traverse object \"%s\"\n", hand[u].obj);
+ /* Initialize iter structure */
+ iter.fid = fid;
+
+ if(H5Fget_filesize(fid, &iter.filesize) < 0)
+ warn_msg("Unable to retrieve file size\n");
+ HDassert(iter.filesize != 0);
+
+ /* Get storge info for file-level structures */
+ if(H5Fget_info2(fid, &finfo) < 0)
+ warn_msg("Unable to retrieve file info\n");
+ else {
+ iter.super_size = finfo.super.super_size;
+ iter.super_ext_size = finfo.super.super_ext_size;
+ iter.SM_hdr_storage_size = finfo.sohm.hdr_size;
+ iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size;
+ iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size;
+ iter.free_space = finfo.free.tot_space;
+ iter.free_hdr = finfo.free.meta_size;
+ } /* end else */
+
+ if((fcpl = H5Fget_create_plist(fid)) < 0)
+ warn_msg("Unable to retrieve file creation property\n");
+
+ if(H5Pget_userblock(fcpl, &iter.ublk_size) < 0)
+ warn_msg("Unable to retrieve userblock size\n");
+
+ if(H5Pget_file_space(fcpl, &iter.fs_strategy, &iter.fs_threshold) < 0)
+ warn_msg("Unable to retrieve file space information\n");
+ HDassert(iter.fs_strategy != 0 && iter.fs_strategy < H5F_FILE_SPACE_NTYPES);
+
+ /* get information for free-space sections */
+ if(freespace_stats(fid, &iter) < 0)
+ warn_msg("Unable to retrieve freespace info\n");
+
+ /* Walk the objects or all file */
+ if(display_object) {
+ unsigned u;
+
+ for(u = 0; u < hand->obj_count; u++) {
+ if(h5trav_visit(fid, hand->obj[u], TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
+ warn_msg("Unable to traverse object \"%s\"\n", hand->obj[u]);
+ else
+ print_statistics(hand->obj[u], &iter);
+ } /* end for */
+ } /* end if */
+ else {
+ if(h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
+ warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname);
else
- print_statistics(hand[u].obj, &iter);
- u++;
- } /* end while */
+ print_statistics("/", &iter);
+ } /* end else */
} /* end if */
- else {
- if (h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
- warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname);
- else
- print_statistics("/", &iter);
- } /* end else */
done:
- if(hand) {
- for (i = 0; i < argc; i++)
- if(hand[i].obj) {
- free(hand[i].obj);
- hand[i].obj=NULL;
- }
+ hand_free(hand);
- free(hand);
- hand = NULL;
+ /* Free iter structure */
+ iter_free(&iter);
- /* Free iter structure */
- iter_free(&iter);
-
- if(fid >= 0 && H5Fclose(fid) < 0) {
- error_msg("unable to close file \"%s\"\n", fname);
- h5tools_setstatus(EXIT_FAILURE);
- }
- }
+ if(fid >= 0 && H5Fclose(fid) < 0) {
+ error_msg("unable to close file \"%s\"\n", fname);
+ h5tools_setstatus(EXIT_FAILURE);
+ } /* end if */
leave(h5tools_getstatus());
-}
+} /* end main() */
diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c
index 528fc40..96b508d 100644
--- a/tools/lib/h5diff_array.c
+++ b/tools/lib/h5diff_array.c
@@ -5783,17 +5783,19 @@ static
int ull2float(unsigned long long ull_value, float *f_value)
{
hid_t dxpl_id;
- unsigned char *buf;
+ unsigned char *buf = NULL;
size_t src_size;
size_t dst_size;
h5difftrace("ull2float start\n");
if((dxpl_id = H5Pcreate(H5P_DATASET_XFER))<0)
- return -1;
+ goto error;
src_size = H5Tget_size(H5T_NATIVE_ULLONG);
dst_size = H5Tget_size(H5T_NATIVE_FLOAT);
buf = (unsigned char*)HDcalloc(1, MAX(src_size, dst_size));
+ if(!buf)
+ goto error;
HDmemcpy(buf, &ull_value, src_size);
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 5f4227c..3e9c43e 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -527,16 +527,18 @@ h5tools_detect_vlen_str(hid_t tid)
}
}
else if(tclass == H5T_COMPOUND) {
- int i = 0;
- int n = H5Tget_nmembers(tid);
+ unsigned nmembs;
+ int snmembs = H5Tget_nmembers(tid);
+ unsigned u;
- if(n < 0) {
- n = ret;
+ if(snmembs < 0) {
+ ret = FAIL;
goto done;
}
+ nmembs = (unsigned)snmembs;
- for(i = 0; i < n; i++) {
- hid_t mtid = H5Tget_member_type(tid, i);
+ for(u = 0; u < nmembs; u++) {
+ hid_t mtid = H5Tget_member_type(tid, u);
ret = h5tools_detect_vlen_str(mtid);
if((ret == TRUE) || (ret < 0)) {
@@ -1150,6 +1152,8 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
s = *(char**) mem;
if (s != NULL)
size = HDstrlen(s);
+ else
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "NULL string");
}
else {
s = (char *) mem;
diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c
index d6cd0a0..b3c8f5e 100644
--- a/tools/lib/h5tools_dump.c
+++ b/tools/lib/h5tools_dump.c
@@ -188,7 +188,7 @@ table_t *h5dump_type_table = NULL; /*type table reference for datatype dump */
static int h5tools_print_region_data_blocks(hid_t region_id,
FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer/*string into which to render */, size_t ncols,
- int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata);
+ unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata);
hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id,
FILE *stream, const h5tool_format_t *info,
@@ -419,7 +419,7 @@ static int
h5tools_print_region_data_blocks(hid_t region_id,
FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer/*string into which to render */, size_t ncols,
- int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata)
+ unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata)
{
hbool_t dimension_break = TRUE;
hsize_t *dims1 = NULL;
@@ -432,9 +432,9 @@ h5tools_print_region_data_blocks(hid_t region_id,
unsigned int region_flags; /* buffer extent flags */
hsize_t numelem;
hsize_t numindex;
- size_t jndx;
unsigned indx;
- int type_size;
+ unsigned jndx;
+ size_t type_size;
int ret_value = SUCCEED;
hid_t mem_space = -1;
hid_t sid1 = -1;
@@ -447,6 +447,7 @@ h5tools_print_region_data_blocks(hid_t region_id,
HDassert(ptdata);
HDmemset(&ctx, 0, sizeof(ctx));
+
/* Get the dataspace of the dataset */
if((sid1 = H5Dget_space(region_id)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
@@ -463,7 +464,7 @@ h5tools_print_region_data_blocks(hid_t region_id,
}
/* Create dataspace for reading buffer */
- if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0)
+ if((mem_space = H5Screate_simple((int)ndims, dims1, NULL)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
if((type_size = H5Tget_size(type_id)) == 0)
@@ -504,7 +505,7 @@ h5tools_print_region_data_blocks(hid_t region_id,
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
/* assume entire data space to be printed */
- for (indx = 0; indx < (size_t) ctx.ndims; indx++)
+ for (indx = 0; indx < (unsigned)ctx.ndims; indx++)
ctx.p_min_idx[indx] = start[indx];
init_acc_pos(&ctx, total_size);
@@ -513,11 +514,11 @@ h5tools_print_region_data_blocks(hid_t region_id,
if (blkndx == nblocks - 1)
region_flags |= END_OF_DATA;
- for (indx = 0; indx < (size_t)ctx.ndims; indx++)
+ for (indx = 0; indx < (unsigned)ctx.ndims; indx++)
ctx.p_max_idx[indx] = dims1[indx];
curr_pos = 0;
- ctx.sm_pos = blkndx*2*ndims;
+ ctx.sm_pos = blkndx * 2 * ndims;
ctx.size_last_dim = dims1[ndims-1];
h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0);
@@ -540,7 +541,7 @@ h5tools_print_region_data_blocks(hid_t region_id,
if(FALSE == dimension_break)
elmtno = 0;
- } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */
+ } /* end for (numindex = 0; numindex < numelem; numindex++, elmtno++, ctx.cur_elmt++) */
ctx.indent_level--;
} /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */
@@ -593,24 +594,28 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
{
HERR_INIT(hbool_t, TRUE)
hbool_t dimension_break = TRUE;
- hssize_t nblocks;
+ hssize_t snblocks;
+ hsize_t nblocks;
hsize_t alloc_size;
hsize_t *ptdata = NULL;
- int ndims;
+ int sndims;
+ unsigned ndims;
hid_t dtype = -1;
hid_t type_id = -1;
- int i;
+ hsize_t u;
HDassert(info);
HDassert(ctx);
HDassert(buffer);
- if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
+ if((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed");
+ nblocks = (hsize_t)snblocks;
/* Print block information */
- if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
+ if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0)
H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ ndims = (unsigned)sndims;
/* Render the region { element begin */
h5tools_str_reset(buffer);
@@ -635,27 +640,26 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
//HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata");
}
- H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t);
- if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0)
+ if(H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, nblocks, ptdata) < 0)
HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed");
- for (i = 0; i < nblocks; i++) {
- int j;
+ for(u = 0; u < nblocks; u++) {
+ unsigned v;
h5tools_str_append(buffer, info->dset_blockformat_pre,
- i ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) i);
+ u ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long)u);
/* Start coordinates and opposite corner */
- for (j = 0; j < ndims; j++)
- h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, j ? "," : "(",
- ptdata[i * 2 * ndims + j]);
+ for (v = 0; v < ndims; v++)
+ h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, v ? "," : "(",
+ ptdata[u * 2 * ndims + v]);
- for (j = 0; j < ndims; j++)
- h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, j ? "," : ")-(",
- ptdata[i * 2 * ndims + j + ndims]);
+ for (v = 0; v < ndims; v++)
+ h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, v ? "," : ")-(",
+ ptdata[u * 2 * ndims + v + ndims]);
h5tools_str_append(buffer, ")");
- } /* end for (i = 0; i < nblocks; i++) */
+ } /* end for (u = 0; u < nblocks; u++) */
dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
/* Render the region datatype info and indices element end */
@@ -2222,12 +2226,16 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_
/* Change the endianness and see if they're equal. */
order = H5Tget_order(tmp_type);
- if (order == H5T_ORDER_LE)
- H5Tset_order(str_type, H5T_ORDER_LE);
- else if (order == H5T_ORDER_BE)
- H5Tset_order(str_type, H5T_ORDER_BE);
-
- if (H5Tequal(tmp_type, str_type)) {
+ if(order == H5T_ORDER_LE) {
+ if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tset_order failed");
+ } /* end if */
+ else if(order == H5T_ORDER_BE) {
+ if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tset_order failed");
+ } /* end if */
+
+ if(H5Tequal(tmp_type, str_type)) {
h5tools_str_append(buffer, "H5T_C_S1;");
goto found_string_type;
}
@@ -2249,12 +2257,16 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_
/* Change the endianness and see if they're equal. */
order = H5Tget_order(tmp_type);
- if (order == H5T_ORDER_LE)
- H5Tset_order(str_type, H5T_ORDER_LE);
- else if (order == H5T_ORDER_BE)
- H5Tset_order(str_type, H5T_ORDER_BE);
-
- if (H5Tequal(tmp_type, str_type)) {
+ if(order == H5T_ORDER_LE) {
+ if(H5Tset_order(str_type, H5T_ORDER_LE) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tset_order failed");
+ } /* end if */
+ else if(order == H5T_ORDER_BE) {
+ if(H5Tset_order(str_type, H5T_ORDER_BE) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tset_order failed");
+ } /* end if */
+
+ if(H5Tequal(tmp_type, str_type)) {
h5tools_str_append(buffer, "H5T_FORTRAN_S1;");
goto found_string_type;
}