diff --git a/hdf/src/hfile.c b/hdf/src/hfile.c index f738c4c7e..84d67f88e 100644 --- a/hdf/src/hfile.c +++ b/hdf/src/hfile.c @@ -3550,3 +3550,15 @@ Hgetntinfo(const int32 numbertype, hdf_ntinfo_t *nt_info) } /* end switch */ return SUCCEED; } /* Hgetntinfo */ + +/* Used in the HI_CLOSE macro in hfile_priv.h */ +#if (FILELIB == UNIXBUFIO) +int +hi_close_stdio(FILE **f) +{ + if (EOF == fclose(*f)) + return FAIL; + *f = NULL; + return SUCCEED; +} +#endif diff --git a/hdf/src/hfile_priv.h b/hdf/src/hfile_priv.h index b7b581813..8a007be4a 100644 --- a/hdf/src/hfile_priv.h +++ b/hdf/src/hfile_priv.h @@ -68,7 +68,7 @@ typedef FILE *hdf_file_t; #define HI_CREATE(p) (fopen((p), "wb+")) #define HI_READ(f, b, n) (((size_t)(n) == (size_t)fread((b), 1, (size_t)(n), (f))) ? SUCCEED : FAIL) #define HI_WRITE(f, b, n) (((size_t)(n) == (size_t)fwrite((b), 1, (size_t)(n), (f))) ? SUCCEED : FAIL) -#define HI_CLOSE(f) (((f = ((fclose(f) == 0) ? NULL : f)) == NULL) ? SUCCEED : FAIL) +#define HI_CLOSE(f) hi_close_stdio(&f) #define HI_FLUSH(f) (fflush(f) == 0 ? SUCCEED : FAIL) #define HI_SEEK(f, o) (fseek((f), (long)(o), SEEK_SET) == 0 ? SUCCEED : FAIL) #define HI_SEEK_CUR(f, o) (fseek((f), (long)(o), SEEK_CUR) == 0 ? SUCCEED : FAIL) @@ -402,6 +402,10 @@ typedef struct functab_t { extern "C" { #endif +#if (FILELIB == UNIXBUFIO) +HDFLIBAPI int hi_close_stdio(FILE **f); +#endif + #ifdef DISKBLOCK_DEBUG HDFLIBAPI const uint8 diskblock_header[4]; diff --git a/mfhdf/test/cdftest.c b/mfhdf/test/cdftest.c index e63ef150c..88b28e9d3 100644 --- a/mfhdf/test/cdftest.c +++ b/mfhdf/test/cdftest.c @@ -45,6 +45,8 @@ static char mrcsid[] = "Id: cdftest.c,v 1.11 1994/01/10 23:07:27 chouck Exp "; #include "hdf4_netcdf.h" #endif +#include "hdftest.h" + #define CDFMAXSHORT 32767 #define CDFMAXLONG 2147483647 #define CDFMAXBYTE 127 @@ -109,10 +111,10 @@ chkgot(nc_type type, union getret got, double check) cdf_assert((nclong)check == got.lng[0]); break; case NC_FLOAT: - cdf_assert((float)check == got.fl[0]); + cdf_assert(H4_FLT_ABS_EQUAL((float)check, got.fl[0])); break; case NC_DOUBLE: - cdf_assert(check == got.dbl); + cdf_assert(H4_DBL_ABS_EQUAL(check, got.dbl)); break; } } @@ -229,12 +231,12 @@ createtestvars(int id, struct tcdfvar *testvars, int count) for (ii = 0; ii < count; ii++, vp++) { cdf_assert(ncvardef(id, vp->mnem, vp->type, vp->ndims, vp->dims) == ii); - cdf_assert(ncattput(id, ii, reqattr[0], NC_CHAR, strlen(vp->units), vp->units) == 0); + cdf_assert(ncattput(id, ii, reqattr[0], NC_CHAR, (int)strlen(vp->units), vp->units) == 0); cdf_assert(ncattput(id, ii, reqattr[1], NC_DOUBLE, 1, (ncvoid *)&(vp->validmin)) == 1); cdf_assert(ncattput(id, ii, reqattr[2], NC_DOUBLE, 1, (ncvoid *)&(vp->validmax)) == 2); cdf_assert(ncattput(id, ii, reqattr[3], NC_DOUBLE, 1, (ncvoid *)&(vp->scalemin)) == 3); cdf_assert(ncattput(id, ii, reqattr[4], NC_DOUBLE, 1, (ncvoid *)&(vp->scalemax)) == 4); - cdf_assert(ncattput(id, ii, reqattr[5], NC_CHAR, strlen(vp->fieldnam), vp->fieldnam) == 5); + cdf_assert(ncattput(id, ii, reqattr[5], NC_CHAR, (int)strlen(vp->fieldnam), vp->fieldnam) == 5); } } @@ -253,7 +255,7 @@ fill_seq(int id) long vindices[NUM_DIMS]; long *cc, *mm; float val; - int ii = 0; + float ii = 0.0F; sizes_g[0] = NUM_RECS; /* zero the indices */ @@ -275,7 +277,7 @@ fill_seq(int id) #endif cdf_assert(ncvarput1(id, Float_id, vindices, (ncvoid *)&val) != -1); (*cc)++; - ii++; + ii += 1.0F; continue; } cc++; @@ -296,7 +298,7 @@ check_fill_seq(int id) long vindices[NUM_DIMS]; long *cc, *mm; union getret got; - int ii = 0; + float ii = 0.0F; float val; sizes_g[0] = NUM_RECS; @@ -313,12 +315,12 @@ check_fill_seq(int id) if (ncvarget1(id, Float_id, vindices, (ncvoid *)&got) == -1) goto bad_ret; val = ii; - if (val != got.fl[0]) { + if (!H4_FLT_ABS_EQUAL(val, got.fl[0])) { parray("indices", (unsigned)NUM_DIMS, vindices); printf("\t%f != %f\n", (double)val, (double)got.fl[0]); } (*cc)++; - ii++; + ii += 1.0F; continue; } cc++; @@ -382,12 +384,12 @@ main(void) cdf_assert(ncattput(id, NC_GLOBAL, "TITLE", NC_CHAR, 12, "another name") != -1); cdf_assert(ncattget(id, NC_GLOBAL, "TITLE", (ncvoid *)new) != -1); /* printf("title 1 \"%s\"\n", new) ; */ - cdf_assert(ncattput(id, NC_GLOBAL, "TITLE", NC_CHAR, strlen(fname), fname) != -1); + cdf_assert(ncattput(id, NC_GLOBAL, "TITLE", NC_CHAR, (int)strlen(fname), fname) != -1); cdf_assert(ncattget(id, NC_GLOBAL, "TITLE", (ncvoid *)new) != -1); new[strlen(fname)] = 0; /* printf("title 2 \"%s\"\n", new) ; */ cdf_assert(strcmp(fname, new) == 0); - cdf_assert(ncattput(id, NC_GLOBAL, "RCSID", NC_CHAR, strlen(mrcsid), (ncvoid *)mrcsid) != -1); + cdf_assert(ncattput(id, NC_GLOBAL, "RCSID", NC_CHAR, (int)strlen(mrcsid), (ncvoid *)mrcsid) != -1); createtestdims(id, NUM_DIMS, sizes_g, dim_names_g); testdims(id, NUM_DIMS, sizes_g, dim_names_g); @@ -480,7 +482,7 @@ main(void) cdf_assert(strcmp("TITLE", adesc->mnem) == 0); cdf_assert(ncattinq(id, NC_GLOBAL, adesc->mnem, &(adesc->type), &(adesc->len)) != -1); cdf_assert(adesc->type == NC_CHAR); - cdf_assert(adesc->len == strlen(fname)); + cdf_assert(adesc->len == (int)strlen(fname)); cdf_assert(ncattget(id, NC_GLOBAL, "TITLE", (ncvoid *)new) != -1); new[adesc->len] = 0; cdf_assert(strcmp(fname, new) == 0); @@ -490,7 +492,7 @@ main(void) cdf_assert(strcmp("RCSID", adesc->mnem) == 0); cdf_assert(ncattinq(id, NC_GLOBAL, adesc->mnem, &(adesc->type), &(adesc->len)) != -1); cdf_assert(adesc->type == NC_CHAR); - cdf_assert(adesc->len == strlen(mrcsid)); + cdf_assert(adesc->len == (int)strlen(mrcsid)); cdf_assert(ncattget(id, NC_GLOBAL, "RCSID", (ncvoid *)new) != -1); new[adesc->len] = 0; cdf_assert(strcmp(mrcsid, new) == 0); @@ -532,7 +534,7 @@ main(void) if (ncattinq(id, ii, reqattr[0], &(adesc->type), &(adesc->len)) != -1) { cdf_assert(adesc->type == NC_CHAR); - cdf_assert(adesc->len == strlen(tvp->units)); + cdf_assert(adesc->len == (int)strlen(tvp->units)); cdf_assert(ncattget(id, ii, reqattr[0], (ncvoid *)new) != -1); new[adesc->len] = 0; cdf_assert(strcmp(tvp->units, new) == 0); @@ -568,7 +570,7 @@ main(void) if (ncattinq(id, ii, reqattr[5], &(adesc->type), &(adesc->len)) != -1) { cdf_assert(adesc->type == NC_CHAR); - cdf_assert(adesc->len == strlen(tvp->fieldnam)); + cdf_assert(adesc->len == (int)strlen(tvp->fieldnam)); cdf_assert(ncattget(id, ii, reqattr[5], (ncvoid *)new) != -1); new[adesc->len] = 0; cdf_assert(strcmp(tvp->fieldnam, new) == 0); diff --git a/mfhdf/test/hdftest.h b/mfhdf/test/hdftest.h index 43b039f3e..5d825ab93 100644 --- a/mfhdf/test/hdftest.h +++ b/mfhdf/test/hdftest.h @@ -160,7 +160,7 @@ int32 make_Ext3D_SDS(int32 sd_id, char *sds_name, int32 type, int32 rank, int32 int32 append_Data2SDS(int32 sd_id, char *sds_name, int32 *start, int32 *edges, void *ap_data); /* Calls SDgetdatasize then verify the size against data_size */ -int verify_datasize(int32 sds_id, int32 data_size, char *sds_name); +int verify_datasize(int32 sds_id, int32 data_size, const char *sds_name); /* Verifies the unlimited dimension's size and the variable's data. */ int verify_info_data(int32 sds_id, int32 expected_dimsize, int16 *result); diff --git a/mfhdf/test/tattributes.c b/mfhdf/test/tattributes.c index 0048d70be..e6546e394 100644 --- a/mfhdf/test/tattributes.c +++ b/mfhdf/test/tattributes.c @@ -372,13 +372,15 @@ test_attribute_ops() /* Get the info about the first attribute of this dimension */ status = SDattrinfo(dimid, (int32)0, name, &nt, &count); CHECK(status, FAIL, "SDattrinfo"); + if (count < 0) + count = 0; /* Read first attribute in, assume CHAR here. */ status = SDreadattr(dimid, 0, text); CHECK(status, FAIL, "SDreadattr"); /* Compare value retrieved to what was written */ - if (strncmp(text, "TRUE", count)) { + if ((status != FAIL) && strncmp(text, "TRUE", (size_t)count)) { fprintf(stderr, "SDreadattr: Invalid dimension attribute read <%s>\n", text); num_errs++; } @@ -613,12 +615,14 @@ test_attribute_ops() /* Get info about the global attribute just created */ status = SDattrinfo(fid1, (int32)0, name, &nt, &count); CHECK(status, FAIL, "SDattrinfo"); + if (count < 0) + count = 0; /* Read this global attribute back in and verify the values */ status = SDreadattr(fid1, 0, text); CHECK(status, FAIL, "SDreadattr"); - if (strncmp(text, "globulator", count)) { + if ((status != FAIL) && strncmp(text, "globulator", (size_t)count)) { fprintf(stderr, "Invalid global attribute read <%s>\n", text); num_errs++; } diff --git a/mfhdf/test/tchunk.c b/mfhdf/test/tchunk.c index cc9f02668..24896c9d5 100644 --- a/mfhdf/test/tchunk.c +++ b/mfhdf/test/tchunk.c @@ -825,14 +825,14 @@ test_chunk() comp_type = COMP_CODE_INVALID; /* reset variables before retrieving info */ status = SDgetcomptype(newsds6, &comp_type); CHECK(status, FAIL, "Chunk Test 6. SDgetcomptype"); - VERIFY(comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcomptype"); + VERIFY((int)comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcomptype"); /* Retrieve and verify the compression info - bug# 307 and bugzilla# 130 */ comp_type = COMP_CODE_INVALID; /* reset variables before retrieving info */ memset(&cinfo, 0, sizeof(cinfo)); status = SDgetcompinfo(newsds6, &comp_type, &cinfo); CHECK(status, FAIL, "Chunk Test 6. SDgetcompinfo"); - VERIFY(comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcompinfo"); + VERIFY((int)comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcompinfo"); VERIFY(cinfo.skphuff.skp_size, chunk_def.comp.cinfo.skphuff.skp_size, "Chunk Test 6. SDgetcompinfo"); /* Write data use SDwriteChunk */ @@ -1036,7 +1036,7 @@ test_chunk() c_flags_out = 0; status = SDgetchunkinfo(newsds6, &chunk_def_out, &c_flags_out); CHECK(status, FAIL, "Chunk Test 6. SDgetchunkinfo"); - VERIFY(chunk_def_out.comp.comp_type, comp_type, "Chunk Test 6. SDgetchunkinfo"); + VERIFY((int)comp_type, chunk_def_out.comp.comp_type, "Chunk Test 6. SDgetchunkinfo"); VERIFY(chunk_def_out.comp.cinfo.skphuff.skp_size, chunk_def.comp.cinfo.skphuff.skp_size, "Chunk Test 6. chunkinfo_new"); VERIFY(c_flags_out, (HDF_CHUNK | HDF_COMP), "Chunk Test 6. SDgetchunkinfo"); @@ -1204,14 +1204,14 @@ test_chunk() memset(&cinfo, 0, sizeof(cinfo)); status = SDgetcompinfo(newsds7, &comp_type, &cinfo); CHECK(status, FAIL, "Chunk Test 6. SDgetcompinfo"); - VERIFY(comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcompinfo"); + VERIFY((int)comp_type, chunk_def.comp.comp_type, "Chunk Test 6. SDgetcompinfo"); VERIFY(cinfo.deflate.level, chunk_def.comp.cinfo.deflate.level, "Chunk Test 6. SDgetcompinfo"); /* Retrieve and verify the compression type */ comp_type = COMP_CODE_INVALID; /* reset variables before retrieving info */ status = SDgetcomptype(newsds7, &comp_type); CHECK(status, FAIL, "Chunk Test 7. SDgetcomptype"); - VERIFY(comp_type, chunk_def.comp.comp_type, "Chunk Test 7. SDgetcomptype"); + VERIFY((int)comp_type, chunk_def.comp.comp_type, "Chunk Test 7. SDgetcomptype"); /* Close down SDS*/ status = SDendaccess(newsds7); diff --git a/mfhdf/test/tcomp.c b/mfhdf/test/tcomp.c index 22d15f8e1..53c68db88 100644 --- a/mfhdf/test/tcomp.c +++ b/mfhdf/test/tcomp.c @@ -56,23 +56,20 @@ static int test_various_comps() { - /************************* Variable declaration **************************/ - int32 sd_id, sds_id; int status; int32 comp_type; /* Compression flag */ comp_info c_info; /* Compression structure */ int32 start[2], edges[2], dim_sizes[2]; int32 data[Y_LENGTH][X_LENGTH]; - int32 pixels_per_scanline; int num_errs = 0; /* number of errors in compression test so far */ - int i, j; - - /********************* End of variable declaration ***********************/ +#ifdef H4_HAVE_SZIP_ENCODER + int32 pixels_per_scanline; +#endif /* Buffer array data and define array dimensions. */ - for (j = 0; j < Y_LENGTH; j++) { - for (i = 0; i < X_LENGTH; i++) + for (int j = 0; j < Y_LENGTH; j++) { + for (int i = 0; i < X_LENGTH; i++) data[j][i] = (i + j) + 1; } dim_sizes[0] = Y_LENGTH; @@ -126,7 +123,10 @@ test_various_comps() status = SDendaccess(sds_id); CHECK(status, FAIL, "SDendaccess"); -#ifdef H4_HAVE_SZIP_ENCODER /* we have szip library with encoder */ +#ifdef H4_HAVE_SZIP_ENCODER + + /* We have an szip library with encoder */ + /* Create 3rd data set for SZIP compression. */ sds_id = SDcreate(sd_id, SDS3_NAME, DFNT_INT32, RANK, dim_sizes); CHECK(sds_id, FAIL, "SDcreate"); @@ -135,7 +135,7 @@ test_various_comps() comp_type = COMP_CODE_SZIP; pixels_per_scanline = dim_sizes[1]; c_info.szip.pixels = dim_sizes[0] * dim_sizes[1]; - ; + c_info.szip.pixels_per_block = 2; if (pixels_per_scanline >= 2048) c_info.szip.pixels_per_scanline = 512; diff --git a/mfhdf/test/tdim.c b/mfhdf/test/tdim.c index bf37229c6..d890f8233 100644 --- a/mfhdf/test/tdim.c +++ b/mfhdf/test/tdim.c @@ -65,7 +65,6 @@ test_basic_dim() int32 dims[2], start[2], edges[2], rank; int16 array1_data[LENGTH0][LENGTH1]; /* data for first SDS */ int32 dim_sizes[H4_MAX_VAR_DIMS]; /* read dimensions */ - int i, j; int32 array_rank, num_type, attributes; char dim_name[H4_MAX_NC_NAME], name[H4_MAX_NC_NAME]; uint8 scale0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 255}; @@ -121,12 +120,12 @@ test_basic_dim() */ /* Fill the buffer with values. */ - for (j = 0; j < LENGTH0; j++) { - for (i = 0; i < LENGTH1; i++) - array1_data[j][i] = (i + j) + 1; + for (int j = 0; j < LENGTH0; j++) { + for (int i = 0; i < LENGTH1; i++) + array1_data[j][i] = (int16)(i + j) + 1; } /* Define the area for writing to the dataset */ - for (i = 0; i < rank; i++) { + for (int i = 0; i < rank; i++) { start[i] = 0; edges[i] = dims[i]; } @@ -198,7 +197,7 @@ test_basic_dim() dims[0] = LENGTH2; dims[1] = LENGTH3; - for (i = 0; i < rank; i++) + for (int i = 0; i < rank; i++) edges[i] = dims[i]; /* Create the data set */ @@ -278,7 +277,6 @@ test_dim_scales() int16 array1_data[LENGTH0][LENGTH1]; /* data for first SDS */ uint32 array2_data[LENGTH2][LENGTH3]; /* data for second SDS */ int32 dim_sizes[H4_MAX_VAR_DIMS]; /* read dimensions */ - int i, j; int32 array_rank, num_type, attributes; char dim_name[H4_MAX_NC_NAME], name[H4_MAX_NC_NAME]; uint8 scale0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 255}; @@ -323,12 +321,12 @@ test_dim_scales() */ /* Fill the buffer with values. */ - for (j = 0; j < LENGTH0; j++) { - for (i = 0; i < LENGTH1; i++) - array1_data[j][i] = (i + j) + 1; + for (int j = 0; j < LENGTH0; j++) { + for (int i = 0; i < LENGTH1; i++) + array1_data[j][i] = (int16)(i + j) + 1; } /* Define the area for writing to the dataset */ - for (i = 0; i < rank; i++) { + for (int i = 0; i < rank; i++) { start[i] = 0; edges[i] = dims[i]; } @@ -407,7 +405,7 @@ test_dim_scales() dims[0] = LENGTH2; dims[1] = LENGTH3; - for (i = 0; i < rank; i++) + for (int i = 0; i < rank; i++) edges[i] = dims[i]; /* Create the data set */ @@ -415,9 +413,9 @@ test_dim_scales() CHECK(sds_id, FAIL, "SDcreate"); /* Fill the stored-data array with values. */ - for (j = 0; j < LENGTH2; j++) { - for (i = 0; i < LENGTH3; i++) - array2_data[j][i] = 10 * (j + i); + for (int j = 0; j < LENGTH2; j++) { + for (int i = 0; i < LENGTH3; i++) + array2_data[j][i] = 10 * (uint32)(j + i); } /* Write the data stored in the array 'array2_data' to the dataset */ @@ -472,7 +470,7 @@ test_dim_scales() /* Read dimension scale values and verify them */ status = SDgetdimscale(dim0_id, (void *)scale2_out); CHECK(status, FAIL, "SDgetdimscale"); - for (i = 0; i < LENGTH2; i++) + for (int i = 0; i < LENGTH2; i++) VERIFY(scale2_out[i], scale2[i], "SDgetdimscale"); /* Terminate access to the array. */ @@ -528,7 +526,6 @@ test_dim_strs() int16 array1_data[LENGTH0][LENGTH1]; /* data for first SDS */ uint32 array2_data[LENGTH2][LENGTH3]; /* data for second SDS */ int32 dim_sizes[H4_MAX_VAR_DIMS]; /* read dimensions */ - int i, j; int32 array_rank, num_type, attributes; char dim_name[H4_MAX_NC_NAME], name[H4_MAX_NC_NAME]; char8 scale2[] = {'d', 'i', 'm', '2'}; @@ -578,13 +575,13 @@ test_dim_strs() */ /* Fill the buffer with values. */ - for (j = 0; j < LENGTH0; j++) { - for (i = 0; i < LENGTH1; i++) - array1_data[j][i] = (i + j) + 1; + for (int j = 0; j < LENGTH0; j++) { + for (int i = 0; i < LENGTH1; i++) + array1_data[j][i] = (int16)(i + j) + 1; } /* Define the area for writing to the dataset */ - for (i = 0; i < rank; i++) { + for (int i = 0; i < rank; i++) { start[i] = 0; edges[i] = dims[i]; } @@ -687,9 +684,9 @@ test_dim_strs() CHECK(sds_id, FAIL, "SDcreate"); /* Fill the stored-data array with values. */ - for (j = 0; j < LENGTH2; j++) { - for (i = 0; i < LENGTH3; i++) - array2_data[j][i] = 10 * (j + i); + for (int j = 0; j < LENGTH2; j++) { + for (int i = 0; i < LENGTH3; i++) + array2_data[j][i] = 10 * (uint32)(j + i); } /* Write the data stored in the array 'array2_data' to the dataset */ diff --git a/mfhdf/test/texternal.c b/mfhdf/test/texternal.c index b4c5b11ae..49793cdea 100644 --- a/mfhdf/test/texternal.c +++ b/mfhdf/test/texternal.c @@ -343,7 +343,7 @@ test_getexternal() char *null_buffer = NULL; int ret_code = 0; - ret_code = SDgetexternalinfo(sds_id, name_len + 1, null_buffer, &offset, &length); + ret_code = SDgetexternalinfo(sds_id, (unsigned)name_len + 1, null_buffer, &offset, &length); VERIFY(ret_code, FAIL, "SDgetexternalinfo"); } @@ -353,7 +353,7 @@ test_getexternal() memset(extfile_name, '\0', (size_t)name_len + 1); /* Call SDgetexternalinfo again and get the external file info */ - name_len = SDgetexternalinfo(sds_id, name_len + 1, extfile_name, &offset, &length); + name_len = SDgetexternalinfo(sds_id, (unsigned)name_len + 1, extfile_name, &offset, &length); VERIFY(name_len, (int)strlen(EXTFILE), "SDgetexternalinfo"); VERIFY_CHAR(EXTFILE, extfile_name, "SDgetexternalinfo"); @@ -369,7 +369,7 @@ test_getexternal() /* Call SDgetexternalinfo again with smaller buffer size and verify that SDgetexternalinfo reads the name truncated to the given buffer size*/ - name_len = SDgetexternalinfo(sds_id, name_len - 2, extfile_name, &offset, &length); + name_len = SDgetexternalinfo(sds_id, (unsigned)name_len - 2, extfile_name, &offset, &length); VERIFY(name_len, (int)strlen(extfile_name), "SDgetexternalinfo"); VERIFY_CHAR(short_name, extfile_name, "SDgetexternalinfo"); free(short_name); @@ -398,7 +398,7 @@ test_getexternal() { char *null_buffer = NULL; int ret_code = 0; - ret_code = SDgetexternalinfo(sds_id, name_len + 1, null_buffer, &offset, &length); + ret_code = SDgetexternalinfo(sds_id, (unsigned)name_len + 1, null_buffer, &offset, &length); VERIFY(ret_code, FAIL, "SDgetexternalinfo"); } @@ -407,7 +407,7 @@ test_getexternal() memset(extfile_name, '\0', (size_t)name_len + 1); /* Call SDgetexternalinfo again and get the external file info */ - name_len = SDgetexternalinfo(sds_id, name_len + 1, extfile_name, &offset, &length); + name_len = SDgetexternalinfo(sds_id, (unsigned)name_len + 1, extfile_name, &offset, &length); VERIFY(name_len, (int)strlen(EXTFILE), "SDgetexternalinfo"); VERIFY_CHAR(EXTFILE, extfile_name, "SDgetexternalinfo"); free(extfile_name); @@ -463,6 +463,10 @@ test_mult_setexternal() int status = SUCCEED; int num_errs = 0; /* number of errors in compression test so far */ + /* Non-const copies to avoid warnings */ + char temp_SDS1[] = SDS1; + char temp_EXTFILE2[] = EXTFILE2; + /* Create the file and initialize the SD interface */ sd_id = SDstart(EXTTST, DFACC_CREATE); CHECK(status, FAIL, "SDstart"); @@ -473,8 +477,8 @@ test_mult_setexternal() /* Create data set SDS1 and write data to the external file; the returned value is the size of the data had been written for this sds */ - size_written = - make_Ext3D_SDS(sd_id, SDS1, DFNT_INT32, 3, dim_sizes, (void *)written_data, OFFSET, EXTFILE2); + size_written = make_Ext3D_SDS(sd_id, temp_SDS1, DFNT_INT32, 3, dim_sizes, (void *)written_data, OFFSET, + temp_EXTFILE2); CHECK(size_written, FAIL, "make_Ext3D_SDS"); /* Close the file to flush */ @@ -513,7 +517,7 @@ test_mult_setexternal() memset(extfile_name, '\0', (size_t)name_len + 1); /* Call SDgetexternalinfo again and get the external file info */ - name_len = SDgetexternalinfo(sds1_id, name_len + 1, extfile_name, NULL, NULL); + name_len = SDgetexternalinfo(sds1_id, (unsigned)name_len + 1, extfile_name, NULL, NULL); VERIFY(name_len, (int)strlen(EXTFILE2), "SDgetexternalinfo"); VERIFY_CHAR(EXTFILE2, extfile_name, "SDgetexternalinfo"); @@ -574,6 +578,9 @@ test_special_combos() int ii, jj, kk; int num_errs = 0; /* number of errors in compression test so far */ + /* Non-const copies to avoid warnings */ + char temp_SDS2[] = SDS2; + /* Create the file and initialize the SD interface */ sd_id = SDstart(EXTTST, DFACC_CREATE); CHECK(status, FAIL, "SDstart"); @@ -610,7 +617,7 @@ test_special_combos() /* Append data to the unlimited-dimension data set SDS2. This should */ /* produce a linked-block element, because SDS3 had been written */ - sds2_size = append_Data2SDS(sd_id, SDS2, ap_start, ap_edges, (void *)ap_data); + sds2_size = append_Data2SDS(sd_id, temp_SDS2, ap_start, ap_edges, (void *)ap_data); CHECK(sds2_size, FAIL, "append_Data2SDS"); /* Select the named data set, id is checked by callee */ @@ -1087,7 +1094,7 @@ verify_data(int32 sd_id, int32 sds_ind) num_elems = Z_LENGTH * Y_LENGTH * X_LENGTH; /* Size of data written */ - data_size = num_elems * sizeof(int); + data_size = num_elems * (int)sizeof(int); edges[0] = Z_LENGTH; } diff --git a/mfhdf/test/tfile.c b/mfhdf/test/tfile.c index 70265f8f4..ee7b9dc32 100644 --- a/mfhdf/test/tfile.c +++ b/mfhdf/test/tfile.c @@ -177,16 +177,27 @@ test_file_inuse() static int test_max_open_files() { - int32 fids[NUM_FILES_HI]; /* holds IDs of opened files */ - char filename[NUM_FILES_HI][10]; /* holds generated file names */ - char readfname[H4_MAX_NC_NAME]; /* file name retrieved from file id */ - int index, status, curr_max, /* curr maximum number of open files allowed in HDF */ + int32 *fids = NULL; /* holds IDs of opened files */ + char **filenames = NULL; /* holds generated file names */ + char readfname[H4_MAX_NC_NAME]; /* file name retrieved from file id */ + int index, status, curr_max, /* curr maximum number of open files allowed in HDF */ sys_limit, /* maximum number of open files allowed by system */ curr_max_bk, /* back up of curr_max */ curr_opened, /* number of files currently being opened */ temp_limit, /* temp var - num of files to be opened in this test */ num_errs = 0; /* number of errors so far */ + /* Allocate memory for arrays */ + fids = calloc(NUM_FILES_HI, sizeof(int32)); + CHECK_ALLOC(fids, "fids", "test_max_open_files"); + + filenames = calloc(NUM_FILES_HI, sizeof(char *)); + CHECK_ALLOC(filenames, "filenames", "test_max_open_files"); + for (int i = 0; i < NUM_FILES_HI; i++) { + filenames[i] = calloc(10, sizeof(char)); + CHECK_ALLOC(filenames[i], "filenames[]", "test_max_open_files"); + } + /* Get the current max and system limit */ status = SDget_maxopenfiles(&curr_max, &sys_limit); CHECK(status, FAIL, "test_maxopenfiles: SDget_maxopenfiles"); @@ -200,8 +211,8 @@ test_max_open_files() all should succeed */ for (index = 0; index < NUM_FILES_LOW; index++) { /* Create a file */ - sprintf(filename[index], "file%i", index); - fids[index] = SDstart(filename[index], DFACC_CREATE); + sprintf(filenames[index], "file%i", index); + fids[index] = SDstart(filenames[index], DFACC_CREATE); CHECK(fids[index], FAIL, "test_maxopenfiles: SDstart"); } /* Get the current max and system limit, the current max should now be at system limit */ @@ -228,11 +239,11 @@ test_max_open_files() VERIFY(curr_max, sys_limit, "test_maxopenfiles: SDreset_maxopenfiles"); /* Reopen the 3 files above, and check the number of opened files again */ - fids[5] = SDstart(filename[5], DFACC_RDWR); + fids[5] = SDstart(filenames[5], DFACC_RDWR); CHECK(fids[5], FAIL, "test_maxopenfiles: SDstart"); - fids[15] = SDstart(filename[15], DFACC_RDWR); + fids[15] = SDstart(filenames[15], DFACC_RDWR); CHECK(fids[15], FAIL, "test_maxopenfiles: SDstart"); - fids[25] = SDstart(filename[25], DFACC_RDWR); + fids[25] = SDstart(filenames[25], DFACC_RDWR); CHECK(fids[25], FAIL, "test_maxopenfiles: SDstart"); curr_opened = SDget_numopenfiles(); VERIFY(curr_opened, NUM_FILES_LOW, "test_maxopenfiles: SDget_numopenfiles"); @@ -255,8 +266,8 @@ test_max_open_files() temp_limit = temp_limit > NUM_FILES_HI ? NUM_FILES_HI : temp_limit; for (index = NUM_FILES_LOW; index < temp_limit; index++) { /* Create a file */ - sprintf(filename[index], "file%i", index); - fids[index] = SDstart(filename[index], DFACC_CREATE); + sprintf(filenames[index], "file%i", index); + fids[index] = SDstart(filenames[index], DFACC_CREATE); /* if SDstart fails due to "too many open files," then adjust temp_limit so that further failure can be prevented, i.e. @@ -276,7 +287,7 @@ test_max_open_files() status = SDend(fids[index]); CHECK(status, FAIL, "test_maxopenfiles: SDend"); - fids[index] = SDstart(filename[index], DFACC_RDWR); + fids[index] = SDstart(filenames[index], DFACC_RDWR); CHECK(fids[index], FAIL, "test_maxopenfiles: SDstart"); } @@ -286,9 +297,9 @@ test_max_open_files() CHECK(status, FAIL, "test_maxopenfiles: SDgetfilename"); /* Verify the file name retrieved against the original */ - if (strcmp(readfname, filename[index])) { + if (strcmp(readfname, filenames[index])) { fprintf(stderr, "SDgetfilename: incorrect file being opened - expected <%s>, retrieved <%s>\n", - filename[index], readfname); + filenames[index], readfname); } } @@ -296,8 +307,15 @@ test_max_open_files() for (index = 0; index < temp_limit; index++) { status = SDend(fids[index]); CHECK(status, FAIL, "test_maxopenfiles: SDend"); - remove(filename[index]); + remove(filenames[index]); } + + /* Free memory */ + free(fids); + for (int i = 0; i < NUM_FILES_HI; i++) + free(filenames[i]); + free(filenames); + return num_errs; } diff --git a/mfhdf/test/tmixed_apis.c b/mfhdf/test/tmixed_apis.c index 08ffc5736..55481fc09 100644 --- a/mfhdf/test/tmixed_apis.c +++ b/mfhdf/test/tmixed_apis.c @@ -378,7 +378,7 @@ test_vdatavgroups() CHECK_ALLOC(refarray, "refarray", "test_vdatavgroups"); /* Now, get the user-created vgroup refs */ - status = Vgetvgroups(fid, 0, num_vgroups, refarray); + status = Vgetvgroups(fid, 0, (unsigned)num_vgroups, refarray); CHECK(status, FAIL, "Vgetvgroups"); VERIFY(status, num_vgroups, "Vgetvgroups"); @@ -418,7 +418,7 @@ test_vdatavgroups() CHECK_ALLOC(refarray, "refarray", "test_vdatavgroups"); /* Now, get the user-created vdata refs */ - status = VSgetvdatas(fid, 0, num_vdatas, refarray); + status = VSgetvdatas(fid, 0, (unsigned)num_vdatas, refarray); CHECK(num_vdatas, FAIL, "VSgetvdatas"); VERIFY(status, num_vdatas, "VSgetvdatas"); diff --git a/mfhdf/test/tncvargetfill.c b/mfhdf/test/tncvargetfill.c index 6793ef737..8944dd4bd 100644 --- a/mfhdf/test/tncvargetfill.c +++ b/mfhdf/test/tncvargetfill.c @@ -655,7 +655,7 @@ test_multidims() *********************************************************************/ static int -test_readings(long max_numrecs) +test_readings(int32 max_numrecs) { int ncid; /* file id */ int var1id, var2id; /* variable ids */ diff --git a/mfhdf/test/tsdsprops.c b/mfhdf/test/tsdsprops.c index ba6a3801a..c66cca5a7 100644 --- a/mfhdf/test/tsdsprops.c +++ b/mfhdf/test/tsdsprops.c @@ -612,10 +612,28 @@ test_valid_args2() int32 d1count[1], d2count[2], d3count[3]; int32 d1stride[1], d2stride[2], d3stride[3]; float32 data1 = 32.0F, outdata1; - int32 data2[D2_X][D2_Y], outdata2[D2_X][D2_Y]; - int16 data3[D3_X][D3_Y][D3_Z], outdata3[D3_X][D3_Y][D3_Z]; - int i, j, k, status; - int num_errs = 0; /* number of errors so far */ + + int32 *data2 = NULL; + int32 *outdata2 = NULL; + int16 *data3 = NULL; + int16 *outdata3 = NULL; + + int32 *ptr32; + int16 *ptr16; + + int status; + int i, j, k; + int num_errs = 0; /* number of errors so far */ + + /* Allocate memory for data buffers */ + data2 = calloc(D2_X * D2_Y, sizeof(int32)); + outdata2 = calloc(D2_X * D2_Y, sizeof(int32)); + data3 = calloc(D3_X * D3_Y * D3_Z, sizeof(int16)); + outdata3 = calloc(D3_X * D3_Y * D3_Z, sizeof(int16)); + CHECK_ALLOC(data2, "data2", "test_valid_args2"); + CHECK_ALLOC(outdata2, "outdata2", "test_valid_args2"); + CHECK_ALLOC(data3, "data3", "test_valid_args2"); + CHECK_ALLOC(outdata3, "outdata3", "test_valid_args2"); /* Create and open the file and initiate the SD interface. */ sd_id = SDstart("b150.hdf", DFACC_CREATE); @@ -635,9 +653,9 @@ test_valid_args2() d2start[0] = d2start[1] = 0; d2count[0] = dims2[0]; d2count[1] = dims2[1]; - for (i = 0; i < D2_X; i++) + for (i = 0, ptr32 = data2; i < D2_X; i++) for (j = 0; j < D2_Y; j++) - data2[i][j] = i * j; + *ptr32++ = i * j; status = makeSDS(sd_id, "data2", DFNT_INT32, 2, dims2, d2start, NULL, d2count, data2); CHECK(status, FAIL, "makeSDS data2"); @@ -650,10 +668,10 @@ test_valid_args2() d3count[0] = dims3[0]; d3count[1] = dims3[1]; d3count[2] = dims3[2]; - for (i = 0; i < D3_X; i++) + for (i = 0, ptr16 = data3; i < D3_X; i++) for (j = 0; j < D3_Y; j++) for (k = 0; k < D3_Z; k++) - data3[i][j][k] = (int16)(i * j * k); + *ptr16++ = (int16)(i * j * k); status = makeSDS(sd_id, "data3", DFNT_INT16, 3, dims3, d3start, NULL, d3count, data3); CHECK(status, FAIL, "makeSDS data3"); @@ -698,13 +716,13 @@ test_valid_args2() d2stride[1] = D2_Y; /* should be D2_Y - 1 */ d2count[0] = D2_X; d2count[1] = 2; - status = SDreaddata(sds_id, d2start, d2stride, d2count, (void *)outdata2); + status = SDreaddata(sds_id, d2start, d2stride, d2count, outdata2); VERIFY(status, FAIL, "SDreaddata"); /* Read second dataset with too many values requested */ d2stride[1] = D2_Y - 1; d2count[1] = 3; /* should be 2 */ - status = SDreaddata(sds_id, d2start, d2stride, d2count, (void *)outdata2); + status = SDreaddata(sds_id, d2start, d2stride, d2count, outdata2); VERIFY(status, FAIL, "SDreaddata"); /* Terminate access to the second dataset */ @@ -721,7 +739,7 @@ test_valid_args2() d3count[0] = 4; /* should be 3 max or smaller stride */ d3count[1] = 2; d3count[2] = 2; - status = SDreaddata(sds_id, d3start, d3stride, d3count, (void *)outdata3); + status = SDreaddata(sds_id, d3start, d3stride, d3count, outdata3); VERIFY(status, FAIL, "SDreaddata"); /* Read again with "correct" arguments */ @@ -733,7 +751,7 @@ test_valid_args2() d3count[0] = 3; d3count[1] = 2; d3count[2] = 2; - status = SDreaddata(sds_id, d3start, d3stride, d3count, (void *)outdata3); + status = SDreaddata(sds_id, d3start, d3stride, d3count, outdata3); CHECK(status, FAIL, "SDreaddata"); /* Terminate access to the third dataset */ @@ -744,6 +762,12 @@ test_valid_args2() status = SDend(sd_id); CHECK(status, FAIL, "SDend"); + /* Free memory for data buffers */ + free(data2); + free(outdata2); + free(data3); + free(outdata3); + /* Return the number of errors that's been kept track of, so far */ return num_errs; } diff --git a/mfhdf/test/tutils.c b/mfhdf/test/tutils.c index 724394fb8..7399ca417 100644 --- a/mfhdf/test/tutils.c +++ b/mfhdf/test/tutils.c @@ -19,10 +19,10 @@ #include "srcdir_str.h" /* Buffer to construct path in and return pointer to */ -static char srcdir_path[1024]; +static char srcdir_path_g[1024]; /* Buffer to construct file in and return pointer to */ -static char srcdir_testpath[1024]; +static char srcdir_testpath_g[1024]; /*------------------------------------------------------------------------- * Function: get_srcdir_filename @@ -42,10 +42,17 @@ get_srcdir_filename(const char *filename) if (NULL == srcdir) return NULL; + memset(srcdir_testpath_g, 0, sizeof(srcdir_testpath_g)); + /* Build path to test file */ - if ((strlen(srcdir) + strlen(filename) + 1) < sizeof(srcdir_testpath)) { - snprintf(srcdir_testpath, sizeof(srcdir_testpath), "%s/%s", srcdir, filename); - return srcdir_testpath; + if ((strlen(srcdir) + strlen(filename) + 1) < sizeof(srcdir_testpath_g)) { + int n = snprintf(srcdir_testpath_g, sizeof(srcdir_testpath_g), "%s/%s", srcdir, filename); + + /* Check for truncation */ + if (n < (int)strlen(srcdir) + (int)strlen(filename) + 1) + return NULL; + else + return srcdir_testpath_g; } /* If not enough space, just return NULL */ @@ -70,10 +77,17 @@ get_srcdir(void) if (NULL == srcdir) srcdir = config_srcdir; + memset(srcdir_path_g, 0, sizeof(srcdir_path_g)); + /* Build path to all test files */ - if ((strlen(srcdir) + 2) < sizeof(srcdir_path)) { - snprintf(srcdir_path, sizeof(srcdir_path), "%s/", srcdir); - return (srcdir_path); + if ((strlen(srcdir) + 2) < sizeof(srcdir_path_g)) { + int n = snprintf(srcdir_path_g, sizeof(srcdir_path_g), "%s/", srcdir); + + /* Check for truncation */ + if (n < (int)strlen(srcdir) + 1) + return NULL; + else + return srcdir_path_g; } else return NULL; @@ -337,7 +351,7 @@ append_Data2SDS(int32 sd_id, char *sds_name, int32 *start, int32 *edges, void *a *********************************************************************/ int -verify_datasize(int32 sds_id, int32 data_size, char *sds_name) +verify_datasize(int32 sds_id, int32 data_size, const char *sds_name) { int32 comp_size = 0, uncomp_size = 0; char msg[80];