diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
commit | d456c2bb82be98bc2b7c1039927eb52258d1a0eb (patch) | |
tree | a7d8a65aef5d962c89b0965c86eb535917c023ad /tools | |
parent | 05264c88788f9bd9b04a58673ded246904210235 (diff) | |
download | hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.zip hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.gz hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.bz2 |
[svn-r4643] Purpose:
Code cleanup
Description:
Windows is generating hundreds of warnings from some of the practices in
the library. Mostly, they are because size_t is 32-bit and hsize_t is
64-bit on Windows and we were carelessly casting the larger values down to
the smaller ones without checking for overflow.
Also, some other small code cleanups,etc.
Solution:
Re-worked some algorithms to eliminate the casts and also added more
overflow checking for assignments and function parameters which needed
casts.
Kent did most of the work, I just went over his changes and fit them into
the the library code a bit better.
Platforms tested:
FreeBSD 4.4 (hawkwind)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gifconv/hdf2gif.c | 8 | ||||
-rw-r--r-- | tools/gifconv/hdfgifwr.c | 2 | ||||
-rw-r--r-- | tools/h5dump/h5dump.c | 7 | ||||
-rw-r--r-- | tools/h5dump/h5dumptst.c | 38 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 6 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 12 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 11 |
7 files changed, 50 insertions, 34 deletions
diff --git a/tools/gifconv/hdf2gif.c b/tools/gifconv/hdf2gif.c index c2ddb10..cc7bab4 100644 --- a/tools/gifconv/hdf2gif.c +++ b/tools/gifconv/hdf2gif.c @@ -16,7 +16,7 @@ */ #include <stdio.h> - +#include <assert.h> #include "gif.h" #define MAX_FILE_LEN 256 @@ -208,8 +208,10 @@ int main(int argc , char **argv) return -1; } - RWidth = dim_sizes[1]; - RHeight = dim_sizes[0]; + assert(dim_sizes[0]==(hsize_t)((int)dim_sizes[0])); + assert(dim_sizes[1]==(hsize_t)((int)dim_sizes[1])); + RWidth = (int)dim_sizes[1]; + RHeight = (int)dim_sizes[0]; #ifdef UNUSED w = dim_sizes[1]; h = dim_sizes[0]; diff --git a/tools/gifconv/hdfgifwr.c b/tools/gifconv/hdfgifwr.c index b13b79a..9804098 100644 --- a/tools/gifconv/hdfgifwr.c +++ b/tools/gifconv/hdfgifwr.c @@ -152,7 +152,9 @@ static unsigned long cur_accum = 0; static int cur_bits = 0; #define MAXCODE(n_bits) ( (1 << (n_bits)) - 1) +#ifndef WIN32 #define min(a,b) ((a>b) ? b : a) +#endif #define XV_BITS 12 /* BITS was already defined on some systems */ #define MSDOS 1 #define HSIZE 5003 /* 80% occupancy */ diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 82b67ca..efb0e42 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -4670,6 +4670,7 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t * UNUSED sset) hsize_t *chsize; int ndims; int i; + hsize_t tempi; char *tmp; char *t_name, *t_tmp, *t_prefix; @@ -4735,9 +4736,9 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t * UNUSED sset) indent += COL; H5Aiterate(did, NULL, dump_function_table->dump_attribute_function, NULL); indent -= COL; - i = H5Dget_storage_size(did); - - if (display_data && (i > 0)) { + tempi = H5Dget_storage_size(did); + + if (display_data && (tempi > 0)) { switch (H5Tget_class(type)) { case H5T_INTEGER: case H5T_FLOAT: diff --git a/tools/h5dump/h5dumptst.c b/tools/h5dump/h5dumptst.c index 9ad987f..4399859 100644 --- a/tools/h5dump/h5dumptst.c +++ b/tools/h5dump/h5dumptst.c @@ -393,17 +393,17 @@ static void test_compound_dt(void) { /* test compound data type */ for (i = 0; i < (int)sdim; i++) { dset1[i].a = i; - dset1[i].b = i*i; - dset1[i].c = 1./(i+1); + dset1[i].b = (float)(i*i); + dset1[i].c = (float)(1./(i+1)); dset2[i].a = i; - dset2[i].b = i+ i*0.1; + dset2[i].b = (float)(i+ i*0.1); dset4[i].a = i; - dset4[i].b = i+3; + dset4[i].b = (float)(i+3); dset5[i].a = i; - dset5[i].b = i*0.1; + dset5[i].b = (float)(i*0.1); } @@ -478,7 +478,7 @@ static void test_compound_dt(void) { /* test compound data type */ dset3[i][j].a[k] = k+j+i; for (k = 0; k < 5; k++) for (l = 0; l < 6; l++) - dset3[i][j].b[k][l] = (k+1)+l+j+i; + dset3[i][j].b[k][l] = (float)((k+1)+l+j+i); } } H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset3); @@ -580,17 +580,17 @@ static void test_compound_dt2(void) { /* test compound data type */ sdim = 10; for (i = 0; i < (int)sdim; i++) { dset1[i].a = i; - dset1[i].b = i*i; - dset1[i].c = 1./(i+1); + dset1[i].b = (float)(i*i); + dset1[i].c = (float)(1./(i+1)); dset2[i].a = i; - dset2[i].b = i+ i*0.1; + dset2[i].b = (float)(i+ i*0.1); dset4[i].a = i; - dset4[i].b = i*1.0; + dset4[i].b = (float)(i*1.0); dset5[i].a = i; - dset5[i].b = i*1.0; + dset5[i].b = (float)(i*1.0); } fid = H5Fcreate(FILE9, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); @@ -826,7 +826,7 @@ float dset2_1[10], dset2_2[3][5]; space = H5Screate_simple(1, dims, NULL); dataset = H5Dcreate(group, "dset2.1", H5T_IEEE_F32BE, space, H5P_DEFAULT); for (i = 0; i < 10; i++) - dset2_1[i] = i*0.1+1; + dset2_1[i] = (float)(i*0.1+1); H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_1); H5Sclose(space); H5Dclose(dataset); @@ -837,7 +837,7 @@ float dset2_1[10], dset2_2[3][5]; dataset = H5Dcreate(group, "dset2.2", H5T_IEEE_F32BE, space, H5P_DEFAULT); for (i = 0; i < 3; i++) for (j = 0; j < 5; j++) - dset2_2[i][j] = (i+1)*j*0.1; + dset2_2[i][j] = (float)((i+1)*j*0.1); H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_2); H5Sclose(space); H5Dclose(dataset); @@ -1693,7 +1693,7 @@ static void test_nestcomp(void) */ for (i = 0; i< 10; i++) { s1[i].a = i; - s1[i].b = i*i; + s1[i].b = (float)(i*i); s1[i].c = 1./(i+1); s1[i].d.a = 65 + i; s1[i].d.b[0] = -100.; @@ -1896,7 +1896,7 @@ static void test_vldatatypes(void) wdata[i].len = i + 1; for (j = 0; j < i + 1; j++) - ((float *)wdata[i].p)[j] = i * 10 + ((float)j) / 10.0; + ((float *)wdata[i].p)[j] = (float)(i * 10 + ((float)j) / 10.0); } /* write out the floats in little-endian format */ @@ -2029,7 +2029,7 @@ static void test_vldatatypes3(void) /* Allocate and initialize VL data to write */ for(i=0; i<SPACE1_DIM1; i++) { wdata[i].i=i*10; - wdata[i].f=(i*20)/3.0; + wdata[i].f=(float)((i*20)/3.0); wdata[i].v.p=malloc((i+1)*sizeof(unsigned int)); wdata[i].v.len=i+1; for(j=0; j<(i+1); j++) @@ -2101,7 +2101,7 @@ static void test_vldatatypes4(void) wdata[i].len=i+1; for(j=0; j<(i+1); j++) { ((s1 *)wdata[i].p)[j].i=i*10+j; - ((s1 *)wdata[i].p)[j].f=(i*20+j)/3.0; + ((s1 *)wdata[i].p)[j].f=(float)((i*20+j)/3.0); } /* end for */ } /* end for */ @@ -2311,7 +2311,7 @@ static void test_array4(void) for(i=0; i<SPACE1_DIM1; i++) for(j=0; j<ARRAY1_DIM1; j++) { wdata[i][j].i=i*10+j; - wdata[i][j].f=i*2.5+j; + wdata[i][j].f=(float)(i*2.5+j); } /* end for */ /* Create file */ @@ -2379,7 +2379,7 @@ static void test_array5(void) for(j=0; j<ARRAY1_DIM1; j++) { wdata[i][j].i=i*10+j; for(k=0; k<ARRAY1_DIM1; k++) - wdata[i][j].f[k]=i*10+j*2.5+k; + wdata[i][j].f[k]=(float)(i*10+j*2.5+k); } /* end for */ /* Create file */ diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 8aa69f9..bfbe251 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -1252,6 +1252,7 @@ list_attr (hid_t obj, const char *attr_name, void * UNUSED op_data) hsize_t size[64], nelmts=1; int ndims, i, n; size_t need; + hsize_t temp_need; void *buf; h5dump_t info; @@ -1314,7 +1315,10 @@ list_attr (hid_t obj, const char *attr_name, void * UNUSED op_data) p_type = h5tools_fixtype(type); } if (p_type>=0) { - need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); + temp_need= nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); + assert(temp_need==(hsize_t)((size_t)temp_need)); + need = (size_t)temp_need; + /*need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));*/ buf = malloc(need); assert(buf); if (H5Aread(attr, p_type, buf)>=0) { diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 569fe2f..c97914a 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -649,7 +649,8 @@ h5tools_dump_simple_subset(FILE *stream, const h5dump_t *info, hid_t dset, ctx.p_min_idx[i] = 0; H5Sget_simple_extent_dims(f_space, total_size, NULL); - ctx.size_last_dim = total_size[ctx.ndims - 1]; + assert(total_size[ctx.ndims - 1]==(hsize_t)((int)(total_size[ctx.ndims - 1]))); + ctx.size_last_dim = (int)(total_size[ctx.ndims - 1]); count = sset->count[ctx.ndims - 1]; sset->count[ctx.ndims - 1] = 1; @@ -819,7 +820,10 @@ h5tools_dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, ctx.p_min_idx[i] = 0; H5Sget_simple_extent_dims(f_space, total_size, NULL); - ctx.size_last_dim = total_size[ctx.ndims - 1]; + /* printf("total_size[ctx.ndims-1]%d\n",total_size[ctx.ndims-1]); + printf("total_size cast %d\n",(int)(total_size[ctx.ndims-1])); */ + /*assert(total_size[ctx.ndims - 1]==(hsize_t)((int)(total_size[ctx.ndims - 1])));*/ + ctx.size_last_dim = (total_size[ctx.ndims - 1]); /* calculate the number of elements we're going to print */ p_nelmts = 1; @@ -975,8 +979,8 @@ h5tools_dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, if (nelmts == 0) return SUCCEED; /*nothing to print*/ - - ctx.size_last_dim = ctx.p_max_idx[ctx.ndims - 1]; + assert(ctx.p_max_idx[ctx.ndims - 1]==(hsize_t)((int)ctx.p_max_idx[ctx.ndims - 1])); + ctx.size_last_dim = (int)(ctx.p_max_idx[ctx.ndims - 1]); /* Print it */ h5tools_dump_simple_data(stream, info, obj_id, &ctx, diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 0e3c5c7..2bc6305 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -786,7 +786,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, } } else if (H5Tget_class(type) == H5T_ARRAY) { int k, ndims; - hsize_t i, dims[H5S_MAX_RANK]; + hsize_t i, dims[H5S_MAX_RANK],temp_nelmts; /* Get the array's base datatype for each element */ memb = H5Tget_super(type); @@ -796,9 +796,12 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, assert(ndims >= 1 && ndims <= H5S_MAX_RANK); /* Calculate the number of array elements */ - for (k = 0, nelmts = 1; k < ndims; k++) - nelmts *= dims[k]; - + for (k = 0, nelmts = 1; k < ndims; k++){ + temp_nelmts = nelmts; + temp_nelmts *= dims[k]; + assert(temp_nelmts==(hsize_t)((size_t)temp_nelmts)); + nelmts = (size_t)temp_nelmts; + } /* Print the opening bracket */ h5tools_str_append(str, "%s", OPT(info->arr_pre, "[")); |