diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2014-03-16 04:44:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2014-03-16 04:44:13 (GMT) |
commit | 164b4c75341ee4aa31dcd47c189e415a36ae35e2 (patch) | |
tree | 121120c9d2df2d601730e4c371afbf5f82004f92 /test | |
parent | 288c7760a4a55d56df7a9019a8522625e305b9b7 (diff) | |
download | hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.zip hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.gz hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.bz2 |
[svn-r24804] Description:
Brought changes from Coverity branch back to trunk, and cleaned up misc.
other warnings & formatting issues:
r20833:
Fixed Coverity 667 and 668 with real integer overflow tests this time.
r20834:
Use HDstrncpy and HDstrncat. --gh
r20835:
Change to use strncpy - use base_len + 1 for line 156, use HDstrlen(path) + 1 for line 159
r20836:
Fixed coverity 585 by casting output of fgetc() to a char.
r20837:
Changed sprintf calls to snprintf with size 1 less than the allocated buffer to address coverity issue #967.
Tested on:
Mac OSX/64 10.9.2 (amazon) w/C++, FORTRAN & parallel
(too minor to require h5committest)
Diffstat (limited to 'test')
-rw-r--r-- | test/H5srcdir.h | 8 | ||||
-rw-r--r-- | test/dt_arith.c | 174 | ||||
-rw-r--r-- | test/h5test.c | 151 |
3 files changed, 160 insertions, 173 deletions
diff --git a/test/H5srcdir.h b/test/H5srcdir.h index 202d050..4f0f439 100644 --- a/test/H5srcdir.h +++ b/test/H5srcdir.h @@ -46,8 +46,8 @@ static const char *H5_get_srcdir_filename(const char *filename) /* Build path to test file */ if((HDstrlen(srcdir) + HDstrlen(filename) + 2) < sizeof(srcdir_testpath)) { - HDstrcpy(srcdir_testpath, srcdir); #ifdef H5_VMS + HDstrcpy(srcdir_testpath, srcdir); if(filename[0] == '[') { char *tmp = filename; @@ -57,8 +57,7 @@ static const char *H5_get_srcdir_filename(const char *filename) else HDstrcat(srcdir_testpath, filename); #else - HDstrcat(srcdir_testpath, "/"); - HDstrcat(srcdir_testpath, filename); + HDsnprintf(srcdir_testpath, sizeof(srcdir_testpath), "%s/%s", srcdir, filename); #endif return(srcdir_testpath); } /* end if */ @@ -77,8 +76,7 @@ static const char *H5_get_srcdir(void) /* Build path to all test files */ if((HDstrlen(srcdir) + 2) < sizeof(srcdir_path)) { - HDstrcpy(srcdir_path, srcdir); - HDstrcat(srcdir_path, "/"); + HDsnprintf(srcdir_path, sizeof(srcdir_path), "%s/", srcdir); return(srcdir_path); } /* end if */ else diff --git a/test/dt_arith.c b/test/dt_arith.c index c3692d0..1922f72 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -531,15 +531,14 @@ except_func(H5T_conv_except_t except_type, hid_t UNUSED src_id, hid_t UNUSED dst * Programmer: Robb Matzke * Tuesday, July 21, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void some_dummy_func(float x) { char s[128]; - sprintf(s, "%g", x); + + HDsnprintf(s, sizeof(s), "%g", x); } @@ -576,7 +575,8 @@ generates_sigfpe(void) HDexit(1); } else if (0==pid) { for (i=0; i<2000; i++) { - for (j=0; j<sizeof(double); j++) dp[j] = HDrand(); + for(j = 0; j < sizeof(double); j++) + dp[j] = (unsigned char)HDrand(); f = (float)d; some_dummy_func((float)f); } @@ -1044,14 +1044,14 @@ test_derived_flt(void) */ src_size = H5Tget_size(H5T_NATIVE_INT); endian = H5Tget_order(H5T_NATIVE_INT); - buf = (unsigned char*)HDmalloc(nelmts * (MAX(src_size, size))); - saved_buf = (unsigned char*)HDmalloc(nelmts * src_size); + buf = (unsigned char *)HDmalloc(nelmts * (MAX(src_size, size))); + saved_buf = (unsigned char *)HDmalloc(nelmts * src_size); HDmemset(buf, 0, nelmts * MAX(src_size, size)); HDmemset(saved_buf, 0, nelmts * src_size); - aligned = (int*)HDcalloc((size_t)1, src_size); + aligned = (int *)HDcalloc((size_t)1, src_size); for(i = 0; i < nelmts * src_size; i++) - buf[i] = saved_buf[i] = HDrand(); + buf[i] = saved_buf[i] = (unsigned char)HDrand(); /* Convert data from native integer to derived floating-point type. * The mantissa is big enough to retain the integer's precision. */ @@ -1077,7 +1077,7 @@ test_derived_flt(void) /* Print errors */ if (0==fails_this_test++) { - sprintf(str, "\nTesting random sw derived floating-point -> derived floating-point conversions"); + HDsnprintf(str, sizeof(str), "\nTesting random sw derived floating-point -> derived floating-point conversions"); printf("%-70s", str); HDfflush(stdout); H5_FAILED(); @@ -1204,13 +1204,13 @@ test_derived_flt(void) src_size = H5Tget_size(tid2); dst_size = H5Tget_size(tid1); endian = H5Tget_order(tid2); - buf = (unsigned char*)HDmalloc(nelmts*(MAX(src_size, dst_size))); - saved_buf = (unsigned char*)HDmalloc(nelmts*src_size); - HDmemset(buf, 0, nelmts*MAX(src_size, dst_size)); + buf = (unsigned char *)HDmalloc(nelmts*(MAX(src_size, dst_size))); + saved_buf = (unsigned char *)HDmalloc(nelmts*src_size); + HDmemset(buf, 0, nelmts * MAX(src_size, dst_size)); HDmemset(saved_buf, 0, nelmts*src_size); for(i=0; i<nelmts*src_size; i++) - buf[i] = saved_buf[i] = HDrand(); + buf[i] = saved_buf[i] = (unsigned char)HDrand(); /* Convert data from the 2nd to the 1st derived floating-point type. * The mantissa and exponent of the 2nd type are big enough to retain @@ -1245,7 +1245,7 @@ test_derived_flt(void) /* Print errors */ if (0==fails_this_test++) { - sprintf(str, "\nTesting random sw derived floating-point -> derived floating-point conversions"); + HDsnprintf(str, sizeof(str), "\nTesting random sw derived floating-point -> derived floating-point conversions"); printf("%-70s", str); HDfflush(stdout); H5_FAILED(); @@ -1514,13 +1514,13 @@ test_derived_integer(void) src_size = H5Tget_size(tid1); dst_size = H5Tget_size(tid2); endian = H5Tget_order(tid1); - buf = (unsigned char*)HDmalloc(nelmts*(MAX(src_size, dst_size))); - saved_buf = (unsigned char*)HDmalloc(nelmts*src_size); - HDmemset(buf, 0, nelmts*MAX(src_size, dst_size)); + buf = (unsigned char *)HDmalloc(nelmts*(MAX(src_size, dst_size))); + saved_buf = (unsigned char *)HDmalloc(nelmts*src_size); + HDmemset(buf, 0, nelmts * MAX(src_size, dst_size)); HDmemset(saved_buf, 0, nelmts*src_size); - for(i=0; i<nelmts*src_size; i++) - buf[i] = saved_buf[i] = HDrand(); + for(i=0; i<nelmts * src_size; i++) + buf[i] = saved_buf[i] = (unsigned char)HDrand(); /* Convert data from the 1st to the 2nd derived integer type. * The precision of the 2nd type are big enough to retain @@ -1547,7 +1547,7 @@ test_derived_integer(void) /* Print errors */ if (0==fails_this_test++) { - sprintf(str, "\nTesting random sw derived integer -> derived integer conversions"); + HDsnprintf(str, sizeof(str), "\nTesting random sw derived integer -> derived integer conversions"); printf("%-70s", str); HDfflush(stdout); H5_FAILED(); @@ -1748,14 +1748,14 @@ test_conv_int_1(const char *name, hid_t src, hid_t dst) /* Sanity checks */ if (OTHER==src_type || OTHER==dst_type) { - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); H5_FAILED(); HDputs(" Unknown data type."); goto error; } else { - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); HDfflush(stdout); @@ -2718,17 +2718,20 @@ my_isnan(dtype_t type, void *val) if (!retval) { if (FLT_FLOAT==type) { float x; + HDmemcpy(&x, val, sizeof(float)); - sprintf(s, "%g", x); + HDsnprintf(s, sizeof(s), "%g", x); } else if (FLT_DOUBLE==type) { double x; + HDmemcpy(&x, val, sizeof(double)); - sprintf(s, "%g", x); + HDsnprintf(s, sizeof(s), "%g", x); #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0 } else if (FLT_LDOUBLE==type) { long double x; + HDmemcpy(&x, val, sizeof(long double)); - sprintf(s, "%Lg", x); + HDsnprintf(s, sizeof(s), "%Lg", x); #endif } else { return 0; @@ -2896,7 +2899,7 @@ test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst) } else if (WIFEXITED(status)) { return WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - sprintf(str, " Child caught signal %d.", WTERMSIG(status)); + HDsnprintf(str, sizeof(str), " Child caught signal %d.", WTERMSIG(status)); HDputs(str); return 1; /*child exit after catching non-SIGFPE signal */ } else { @@ -2952,16 +2955,16 @@ test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst) HDputs("Sizeof(float)==sizeof(double) - some tests may not be sensible."); if (OTHER==src_type || OTHER==dst_type) { if(!strcmp(name, "noop")) - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_SPECIAL) - sprintf(str, "Testing %s special %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_NORMAL) - sprintf(str, "Testing %s normalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_DENORM) - sprintf(str, "Testing %s denormalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); @@ -2970,16 +2973,16 @@ test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst) goto error; } else { if(!strcmp(name, "noop")) - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_SPECIAL) - sprintf(str, "Testing %s special %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_NORMAL) - sprintf(str, "Testing %s normalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_DENORM) - sprintf(str, "Testing %s denormalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); @@ -3097,10 +3100,10 @@ test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst) /* Check the software results against the hardware */ for (j=0; j<nelmts; j++) { underflow = 0; - hw_f = 911.0; - hw_d = 911.0; + hw_f = 911.0f; + hw_d = 911.0f; #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE - hw_ld = 911.0; + hw_ld = 911.0f; #endif /* The hardware conversion */ @@ -3174,10 +3177,11 @@ test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst) * 0s before compare the values. */ #if H5_SIZEOF_LONG_DOUBLE !=0 - if(sendian==H5T_ORDER_LE && dst_type==FLT_LDOUBLE) { - unsigned int q; - for(q=dst_nbits/8; q<dst_size; q++) { - buf[j*dst_size+q] = 0x00; + if(sendian == H5T_ORDER_LE && dst_type == FLT_LDOUBLE) { + size_t q; + + for(q = dst_nbits / 8; q < dst_size; q++) { + buf[j * dst_size + q] = 0x00; hw[q] = 0x00; } } @@ -3652,7 +3656,7 @@ test_conv_int_fp(const char *name, int run_test, hid_t src, hid_t dst) /* Sanity checks */ if (OTHER==src_type || OTHER==dst_type) { - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); H5_FAILED(); @@ -3661,15 +3665,15 @@ test_conv_int_fp(const char *name, int run_test, hid_t src, hid_t dst) } if ((INT_SCHAR==src_type || INT_UCHAR==src_type || INT_SHORT==src_type || - INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type || - INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type || - INT_ULLONG==src_type) && - (FLT_FLOAT!=dst_type && FLT_DOUBLE!=dst_type + INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type || + INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type || + INT_ULLONG==src_type) && + (FLT_FLOAT!=dst_type && FLT_DOUBLE!=dst_type #if H5_SIZEOF_LONG_DOUBLE !=0 - && FLT_LDOUBLE!=dst_type + && FLT_LDOUBLE!=dst_type #endif - )) { - sprintf(str, "Testing %s %s -> %s conversions", + )) { + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); H5_FAILED(); @@ -3679,14 +3683,14 @@ test_conv_int_fp(const char *name, int run_test, hid_t src, hid_t dst) if ((FLT_FLOAT==src_type || FLT_DOUBLE==src_type #if H5_SIZEOF_LONG_DOUBLE !=0 - || FLT_LDOUBLE==src_type + || FLT_LDOUBLE==src_type #endif - ) - && (INT_SCHAR!=dst_type && INT_UCHAR!=dst_type && INT_SHORT!=dst_type - && INT_USHORT!=dst_type && INT_INT!=dst_type && INT_UINT!=dst_type - && INT_LONG!=dst_type && INT_ULONG!=dst_type && INT_LLONG!=dst_type - && INT_ULLONG!=dst_type)) { - sprintf(str, "Testing %s %s -> %s conversions", + ) + && (INT_SCHAR!=dst_type && INT_UCHAR!=dst_type && INT_SHORT!=dst_type + && INT_USHORT!=dst_type && INT_INT!=dst_type && INT_UINT!=dst_type + && INT_LONG!=dst_type && INT_ULONG!=dst_type && INT_LLONG!=dst_type + && INT_ULLONG!=dst_type)) { + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); H5_FAILED(); @@ -3695,23 +3699,23 @@ test_conv_int_fp(const char *name, int run_test, hid_t src, hid_t dst) } if (INT_SCHAR==src_type || INT_UCHAR==src_type || INT_SHORT==src_type || - INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type || - INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type || - INT_ULLONG==src_type) { - sprintf(str, "Testing %s %s -> %s conversions", + INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type || + INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type || + INT_ULLONG==src_type) { + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); HDfflush(stdout); fails_this_test=0; } else { if(run_test==TEST_NORMAL) - sprintf(str, "Testing %s normalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions", name, src_type_name, dst_type_name); else if(run_test==TEST_DENORM) - sprintf(str, "Testing %s denormalized %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions", name, src_type_name, dst_type_name); else - sprintf(str, "Testing %s special %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions", name, src_type_name, dst_type_name); printf("%-70s", str); HDfflush(stdout); @@ -5125,13 +5129,13 @@ run_int_fp_conv(const char *name) { char str[256]; /*hello string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "unsigned long long", "float"); printf("%-70s", str); SKIPPED(); HDputs(" Test skipped due to compiler not handling conversion."); - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "unsigned long long", "double"); printf("%-70s", str); SKIPPED(); @@ -5153,19 +5157,19 @@ run_int_fp_conv(const char *name) nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LONG, H5T_NATIVE_LDOUBLE); nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULONG, H5T_NATIVE_LDOUBLE); #else - { - char str[256]; /*string */ + { + char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", - name, "(unsigned) long", "long double"); - printf("%-70s", str); - SKIPPED(); + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", + name, "(unsigned) long", "long double"); + printf("%-70s", str); + SKIPPED(); #if H5_SIZEOF_LONG_DOUBLE!=0 - HDputs(" Test skipped due to the special algorithm of hardware conversion."); + HDputs(" Test skipped due to the special algorithm of hardware conversion."); #else - HDputs(" Test skipped due to disabled long double."); + HDputs(" Test skipped due to disabled long double."); #endif - } + } #endif #endif /* H5_SIZEOF_LONG!=H5_SIZEOF_INT */ #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG @@ -5175,7 +5179,7 @@ run_int_fp_conv(const char *name) { char str[256]; /*hello string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long long", "long double"); printf("%-70s", str); SKIPPED(); @@ -5188,7 +5192,7 @@ run_int_fp_conv(const char *name) { char str[256]; /*hello string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "unsigned long long", "long double"); printf("%-70s", str); SKIPPED(); @@ -5201,7 +5205,7 @@ run_int_fp_conv(const char *name) { char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "all integers", "long double"); printf("%-70s", str); SKIPPED(); @@ -5290,13 +5294,13 @@ run_fp_int_conv(const char *name) { char str[256]; /*hello string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "float", "unsigned long long"); printf("%-70s", str); SKIPPED(); HDputs(" Test skipped due to hardware conversion error."); - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "double", "unsigned long long"); printf("%-70s", str); SKIPPED(); @@ -5318,7 +5322,7 @@ run_fp_int_conv(const char *name) { char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long double", "unsigned int"); printf("%-70s", str); SKIPPED(); @@ -5337,7 +5341,7 @@ run_fp_int_conv(const char *name) { char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long double", "(unsigned) long"); printf("%-70s", str); SKIPPED(); @@ -5357,7 +5361,7 @@ run_fp_int_conv(const char *name) { char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long double", "long long"); printf("%-70s", str); SKIPPED(); @@ -5374,7 +5378,7 @@ run_fp_int_conv(const char *name) { char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long double", "unsigned long long"); printf("%-70s", str); SKIPPED(); @@ -5391,7 +5395,7 @@ run_fp_int_conv(const char *name) { char str[256]; /*hello string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "long double", "all integers"); printf("%-70s", str); SKIPPED(); @@ -5412,7 +5416,7 @@ run_fp_int_conv(const char *name) */ char str[256]; /*string */ - sprintf(str, "Testing %s %s -> %s conversions", + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", name, "all floating-point numbers", "all integers"); printf("%-70s", str); SKIPPED(); diff --git a/test/h5test.c b/test/h5test.c index a5f81ef..3b7bfbe 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -131,63 +131,61 @@ h5_errors(hid_t estack, void UNUSED *client_data) * Programmer: Albert Cheng * May 28, 1998 * - * Modifications: - * Albert Cheng, 2000-09-09 - * Added the explicite base_name argument to replace the - * global variable FILENAME. - * *------------------------------------------------------------------------- */ int h5_cleanup(const char *base_name[], hid_t fapl) { - char filename[1024]; - char temp[2048]; - int i, j; - int retval=0; - hid_t driver; + int retval = 0; + + if(GetTestCleanup()) { + int i; - if (GetTestCleanup()){ - for (i = 0; base_name[i]; i++) { - if (h5_fixname(base_name[i], fapl, filename, sizeof(filename)) == NULL) - continue; + for(i = 0; base_name[i]; i++) { + char filename[1024]; + char temp[2048]; + hid_t driver; + + if(NULL == h5_fixname(base_name[i], fapl, filename, sizeof(filename))) + continue; driver = H5Pget_driver(fapl); - if (driver == H5FD_FAMILY) { - for (j = 0; /*void*/; j++) { - HDsnprintf(temp, sizeof temp, filename, j); + if(driver == H5FD_FAMILY) { + int j; + + for(j = 0; /*void*/; j++) { + HDsnprintf(temp, sizeof temp, filename, j); - if (HDaccess(temp, F_OK) < 0) + if(HDaccess(temp, F_OK) < 0) break; - HDremove(temp); - } - } else if (driver == H5FD_CORE) { + HDremove(temp); + } /* end for */ + } else if(driver == H5FD_CORE) { hbool_t backing; /* Whether the core file has backing store */ - H5Pget_fapl_core(fapl,NULL,&backing); + H5Pget_fapl_core(fapl, NULL, &backing); /* If the file was stored to disk with bacing store, remove it */ if(backing) HDremove(filename); + } else if (driver == H5FD_MULTI) { + H5FD_mem_t mt; - } else if (driver == H5FD_MULTI) { - H5FD_mem_t mt; - assert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); + HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); - for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { - HDsnprintf(temp, sizeof temp, "%s-%c.h5", - filename, multi_letters[mt]); - HDremove(temp); /*don't care if it fails*/ - } - } else { - HDremove(filename); - } - } + for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { + HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); + HDremove(temp); /*don't care if it fails*/ + } /* end for */ + } else { + HDremove(filename); + } + } /* end for */ - retval = 1; - } + retval = 1; + } /* end if */ H5Pclose(fapl); return retval; @@ -204,8 +202,6 @@ h5_cleanup(const char *base_name[], hid_t fapl) * Programmer: Robb Matzke * Friday, November 20, 1998 * - * Modifications: - * *------------------------------------------------------------------------- */ void @@ -267,16 +263,6 @@ h5_reset(void) * Programmer: Robb Matzke * Thursday, November 19, 1998 * - * Modifications: - * Robb Matzke, 1999-08-03 - * Modified to use the virtual file layer. - * - * Albert Cheng, 2000-01-25 - * Added prefix for parallel test files. - * - * Albert Cheng, 2003-05-08 - * Changed the default parallel prefix back to NULL but added - * an explanation remark of $HDF5_PARAPREFIX. *------------------------------------------------------------------------- */ char * @@ -292,37 +278,36 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) if (!base_name || !fullname || size < 1) return NULL; - memset(fullname, 0, size); + HDmemset(fullname, 0, size); /* figure out the suffix */ - if (H5P_DEFAULT != fapl) { - if ((driver = H5Pget_driver(fapl)) < 0) + if(H5P_DEFAULT != fapl) { + if((driver = H5Pget_driver(fapl)) < 0) return NULL; - if (H5FD_FAMILY == driver) - suffix = "%05d.h5"; - else if (H5FD_MULTI == driver) - suffix = NULL; + if(H5FD_FAMILY == driver) + suffix = "%05d.h5"; + else if (H5FD_MULTI == driver) + suffix = NULL; } /* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX * could be of value -1 if it is not defined. */ - isppdriver = H5P_DEFAULT != fapl && - (H5FD_MPIO==driver || H5FD_MPIPOSIX==driver); + isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO==driver || H5FD_MPIPOSIX==driver); /* Check HDF5_NOCLEANUP environment setting. * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ - if (isppdriver){ + if(isppdriver) { #ifdef H5_HAVE_PARALLEL - if (getenv_all(MPI_COMM_WORLD, 0, "HDF5_NOCLEANUP")) - SetTestNoCleanup(); + if(getenv_all(MPI_COMM_WORLD, 0, "HDF5_NOCLEANUP")) + SetTestNoCleanup(); #endif /* H5_HAVE_PARALLEL */ - }else{ - if (HDgetenv("HDF5_NOCLEANUP")) - SetTestNoCleanup(); + } else { + if(HDgetenv("HDF5_NOCLEANUP")) + SetTestNoCleanup(); } /* Check what prefix to use for test files. Process HDF5_PARAPREFIX and @@ -331,7 +316,7 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ - if (isppdriver){ + if(isppdriver) { #ifdef H5_HAVE_PARALLEL /* * For parallel: @@ -340,38 +325,38 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) */ static int explained = 0; - prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX")); + prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX")); - if (!prefix && !explained) { - /* print hint by process 0 once. */ - int mpi_rank; + if (!prefix && !explained) { + /* print hint by process 0 once. */ + int mpi_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); - if (mpi_rank == 0) - printf("*** Hint ***\n" - "You can use environment variable HDF5_PARAPREFIX to " - "run parallel test files in a\n" - "different directory or to add file type prefix. E.g.,\n" - " HDF5_PARAPREFIX=pfs:/PFS/user/me\n" - " export HDF5_PARAPREFIX\n" - "*** End of Hint ***\n"); + if (mpi_rank == 0) + printf("*** Hint ***\n" + "You can use environment variable HDF5_PARAPREFIX to " + "run parallel test files in a\n" + "different directory or to add file type prefix. E.g.,\n" + " HDF5_PARAPREFIX=pfs:/PFS/user/me\n" + " export HDF5_PARAPREFIX\n" + "*** End of Hint ***\n"); - explained = TRUE; + explained = TRUE; #ifdef HDF5_PARAPREFIX prefix = HDF5_PARAPREFIX; #endif /* HDF5_PARAPREFIX */ - } + } #endif /* H5_HAVE_PARALLEL */ } else { - /* + /* * For serial: * First use the environment variable, then try the constant - */ - prefix = HDgetenv("HDF5_PREFIX"); + */ + prefix = HDgetenv("HDF5_PREFIX"); #ifdef HDF5_PREFIX - if (!prefix) + if (!prefix) prefix = HDF5_PREFIX; #endif /* HDF5_PREFIX */ } |