diff options
-rw-r--r-- | fortran/src/H5Pf.c | 77 | ||||
-rw-r--r-- | fortran/src/H5match_types.c | 23 | ||||
-rw-r--r-- | hl/examples/ex_image2.c | 17 | ||||
-rw-r--r-- | perform/pio_engine.c | 3 | ||||
-rw-r--r-- | perform/sio_engine.c | 3 | ||||
-rw-r--r-- | src/H5HGdbg.c | 74 | ||||
-rw-r--r-- | src/H5HLdbg.c | 26 | ||||
-rw-r--r-- | src/H5Lexternal.c | 12 | ||||
-rw-r--r-- | src/H5Oattr.c | 20 | ||||
-rw-r--r-- | src/H5Oefl.c | 11 | ||||
-rw-r--r-- | src/H5system.c | 24 | ||||
-rw-r--r-- | test/h5test.c | 8 | ||||
-rw-r--r-- | tools/h5dump/h5dump_xml.c | 110 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 36 | ||||
-rw-r--r-- | tools/misc/h5debug.c | 5 |
15 files changed, 231 insertions, 218 deletions
diff --git a/fortran/src/H5Pf.c b/fortran/src/H5Pf.c index 262ce55..cf10efc 100644 --- a/fortran/src/H5Pf.c +++ b/fortran/src/H5Pf.c @@ -324,30 +324,23 @@ nh5pset_chunk_c ( hid_t_f *prp_id, int_f *rank, hsize_t_f *dims ) /******/ { int ret_value = -1; - hid_t c_prp_id; - int c_rank; - hsize_t *c_dims; + hid_t c_prp_id = (hid_t)*prp_id; + int c_rank = (int)*rank; + hsize_t c_dims[H5S_MAX_RANK]; herr_t status; int i; - c_dims = (hsize_t *)HDmalloc(sizeof(hsize_t) * (*rank )); - if (!c_dims) return ret_value; - /* * Transpose dimension arrays because of C-FORTRAN storage order */ - for (i = 0; i < *rank ; i++) { - c_dims[i] = dims[*rank - i - 1]; - } + for (i = 0; i < c_rank ; i++) + c_dims[i] = (hsize_t)dims[c_rank - i - 1]; - c_prp_id = (hid_t)*prp_id; - c_rank = (int)*rank; status = H5Pset_chunk(c_prp_id, c_rank, c_dims); if (status < 0) goto DONE; ret_value = 0; DONE: - HDfree (c_dims); return ret_value; } @@ -375,26 +368,19 @@ nh5pget_chunk_c ( hid_t_f *prp_id, int_f *max_rank, hsize_t_f *dims ) /******/ { int ret_value = -1; - hid_t c_prp_id; - hsize_t *c_dims; + hid_t c_prp_id = (hid_t)*prp_id; + hsize_t c_dims[H5S_MAX_RANK]; int rank; - int c_max_rank; + int c_max_rank = (int)*max_rank; int i; - c_dims = (hsize_t *)HDmalloc(sizeof(hsize_t) * (*max_rank )); - if (!c_dims) return ret_value; - - c_prp_id = (hid_t)*prp_id; - c_max_rank = (int)*max_rank; rank = H5Pget_chunk(c_prp_id, c_max_rank, c_dims); /* * Transpose dimension arrays because of C-FORTRAN storage order */ - for (i = 0; i < *max_rank ; i++) { - dims[*max_rank - i - 1] = (hsize_t_f)c_dims[i]; - } - HDfree (c_dims); + for (i = 0; i < c_max_rank ; i++) + dims[c_max_rank - i - 1] = (hsize_t_f)c_dims[i]; if (rank < 0) return ret_value; ret_value = (int_f)rank; return ret_value; @@ -1801,18 +1787,15 @@ nh5pset_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_nel /******/ { int ret_value = -1; - hid_t c_prp_id; + hid_t c_prp_id = (hid_t)*prp_id; herr_t ret; - size_t c_cd_nelmts; - unsigned int c_flags; - H5Z_filter_t c_filter; + size_t c_cd_nelmts = (size_t)*cd_nelmts; + unsigned int c_flags = (unsigned)*flags; + H5Z_filter_t c_filter = (H5Z_filter_t)*filter; unsigned int * c_cd_values; unsigned i; - c_filter = (H5Z_filter_t)*filter; - c_flags = (unsigned)*flags; - c_cd_nelmts = (size_t)*cd_nelmts; - c_cd_values = (unsigned int*)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts)); + c_cd_values = (unsigned int*)HDmalloc(sizeof(unsigned int) * c_cd_nelmts); if (!c_cd_values) return ret_value; for (i = 0; i < c_cd_nelmts; i++) c_cd_values[i] = (unsigned int)cd_values[i]; @@ -1820,7 +1803,6 @@ nh5pset_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_nel /* * Call H5Pset_filter function. */ - c_prp_id = (hid_t)*prp_id; ret = H5Pset_filter(c_prp_id, c_filter, c_flags, c_cd_nelmts,c_cd_values ); if (ret < 0) goto DONE; @@ -1967,13 +1949,12 @@ nh5pset_external_c (hid_t_f *prp_id, _fcd name, int_f* namelen, off_t_f* offset, herr_t ret; hsize_t c_bytes; char* c_name; - size_t c_namelen; + size_t c_namelen = (size_t)*namelen; off_t c_offset; c_bytes = (hsize_t) *bytes; c_offset = (off_t) *offset; - c_namelen = (int)*namelen; c_name = (char *)HD5f2cstring(name, c_namelen); if (c_name == NULL) return ret_value; @@ -3819,7 +3800,7 @@ nh5pset_fapl_multi_c ( hid_t_f *prp_id , int_f *memb_map, hid_t_f *memb_fapl, _f * Check that we got correct values from Fortran for memb_addr array */ for (i=0; i < H5FD_MEM_NTYPES; i++) { - if(memb_addr[i] >= 1.) return ret_value; + if(memb_addr[i] >= 1.0f) return ret_value; } /* * Take care of names array @@ -3971,7 +3952,7 @@ HD5packFstring(tmp, _fcdtocp(memb_name), (size_t)(c_lenmax*H5FD_MEM_NTYPES)); memb_map[i] = (int_f)c_memb_map[i]; memb_fapl[i] = (hid_t_f)c_memb_fapl[i]; if(c_memb_addr[i] == HADDR_UNDEF) memb_addr[i] = -1; - else memb_addr[i] = (real_f) ((long)c_memb_addr[i]/HADDR_MAX); + else memb_addr[i] = (real_f) (c_memb_addr[i]/HADDR_MAX); } *flag = (int_f)relax; *maxlen_out = (int_f)length; @@ -4104,7 +4085,7 @@ nh5pget_filter_by_id_c(hid_t_f *prp_id, int_f* filter_id, int_f* flags, size_t_f if(NULL == (c_name = (char *)HDmalloc((size_t)*namelen + 1))) goto DONE; - if(NULL == (c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts_in)))) + if(NULL == (c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * c_cd_nelmts_in))) goto DONE; /* @@ -4157,18 +4138,15 @@ nh5pmodify_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_ /******/ { int_f ret_value = -1; - hid_t c_prp_id; + hid_t c_prp_id = (hid_t)*prp_id; herr_t ret; - size_t c_cd_nelmts; - unsigned int c_flags; - H5Z_filter_t c_filter; + size_t c_cd_nelmts = (size_t)*cd_nelmts; + unsigned int c_flags = (unsigned)*flags; + H5Z_filter_t c_filter = (H5Z_filter_t)*filter; unsigned int * c_cd_values; unsigned i; - c_filter = (H5Z_filter_t)*filter; - c_flags = (unsigned)*flags; - c_cd_nelmts = (size_t)*cd_nelmts; - c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts)); + c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * c_cd_nelmts); if (!c_cd_values) return ret_value; for (i = 0; i < c_cd_nelmts; i++) c_cd_values[i] = (unsigned int)cd_values[i]; @@ -4176,7 +4154,6 @@ nh5pmodify_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_ /* * Call H5Pmodify_filter function. */ - c_prp_id = (hid_t)*prp_id; ret = H5Pmodify_filter(c_prp_id, c_filter, c_flags, c_cd_nelmts,c_cd_values ); if (ret < 0) goto DONE; @@ -4905,12 +4882,10 @@ nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_l /******/ { char *c_expression = NULL; /* Buffer to hold C string */ - size_t c_expression_len; + size_t c_expression_len = (size_t)*expression_len + 1; ssize_t ret; int_f ret_value = 0; - c_expression_len = (size_t)*expression_len + 1; - /* * Allocate memory to store the expression. */ @@ -4928,7 +4903,7 @@ nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_l HGOTO_DONE(FAIL) /* or strlen ? */ - HD5packFstring(c_expression, _fcdtocp(expression), c_expression_len - 1); + HD5packFstring(c_expression, _fcdtocp(expression), (size_t)*expression_len); *size = (size_t_f)ret; diff --git a/fortran/src/H5match_types.c b/fortran/src/H5match_types.c index eb30775..3fa0efc 100644 --- a/fortran/src/H5match_types.c +++ b/fortran/src/H5match_types.c @@ -51,8 +51,8 @@ FILE * fort_header; void writeTypedef(const char* c_type, unsigned int size); void writeFloatTypedef(const char* c_type, unsigned int size); void writeTypedefDefault(unsigned int size); -void writeToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind); -void writeFloatToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind); +void writeToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind); +void writeFloatToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind); static void initCfile(void) @@ -141,26 +141,26 @@ void writeTypedefDefault(unsigned int size) } /* Create matching Fortran and C types by writing to both files */ -void writeToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind) +void writeToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind) { fprintf(fort_header, " INTEGER, PARAMETER :: %s = %u\n", fortran_type, kind); - fprintf(c_header, "typedef c_int_%u %s;\n", size, c_type); + fprintf(c_header, "typedef c_int_%d %s;\n", size, c_type); } /* Create matching Fortran and C floating types by writing to both files */ -void writeFloatToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind) +void writeFloatToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind) { fprintf(fort_header, " INTEGER, PARAMETER :: %s = %u\n", fortran_type, kind); - fprintf(c_header, "typedef c_float_%u %s;\n", size, c_type); + fprintf(c_header, "typedef c_float_%d %s;\n", size, c_type); } int main(void) { int FoundIntSize[4]; - int FoundIntSizeKind[4]; + unsigned FoundIntSizeKind[4]; int FoundRealSize[3]; - int FoundRealSizeKind[3]; + unsigned FoundRealSizeKind[3]; int i,j,flag; char chrA[20],chrB[20]; int H5_C_HAS_REAL_NATIVE_16; @@ -428,9 +428,7 @@ int main(void) } } if(flag == 0) /* No higher or lower one found, indicating an error */ - { return -1; - } } } @@ -496,9 +494,8 @@ int main(void) { sprintf(chrA, "Fortran_REAL_%d", (-1)*FoundRealSize[i]); sprintf(chrB, "real_%d_f", (-1)*FoundRealSize[i]); - if(FoundRealSize[j]>4) { + if(FoundRealSize[j]>4) writeFloatToFiles(chrA, chrB, FoundRealSize[j], FoundRealSizeKind[j]); - } /* else { */ /* writeFloatToFiles(chrA, chrB, FoundRealSize[j]); */ /* } */ @@ -508,9 +505,7 @@ int main(void) } } if(flag == 0) /* No higher or lower one found, indicating an error */ - { return -1; - } } } diff --git a/hl/examples/ex_image2.c b/hl/examples/ex_image2.c index 76c3a75..3276f7c 100644 --- a/hl/examples/ex_image2.c +++ b/hl/examples/ex_image2.c @@ -26,7 +26,7 @@ #define PAL_ENTRIES 256 static int read_data(const char* file_name, hsize_t *width, hsize_t *height ); -unsigned char *gbuf = 0; /* global buffer for image data */ +unsigned char *gbuf = NULL; /* global buffer for image data */ int main( void ) { @@ -79,18 +79,25 @@ int main( void ) /* make dataset */ status=H5IMmake_image_24bit( file_id, IMAGE2_NAME, width, height, "INTERLACE_PIXEL", gbuf ); - if (gbuf) { - free(gbuf); - gbuf = NULL; - } /* close the file. */ H5Fclose( file_id ); + if(gbuf) { + free(gbuf); + gbuf = NULL; + } + return 0; out: printf("Error on return function...Exiting\n"); + + if(gbuf) { + free(gbuf); + gbuf = NULL; + } + return 1; } diff --git a/perform/pio_engine.c b/perform/pio_engine.c index 87fa82c..d34fe38 100644 --- a/perform/pio_engine.c +++ b/perform/pio_engine.c @@ -464,7 +464,8 @@ pio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si } else { /* We didn't append the prefix yet */ - HDstrncpy(fullname, prefix, MIN(HDstrlen(prefix), size)); + HDstrncpy(fullname, prefix, size); + fullname[size - 1] = '\0'; } if ((HDstrlen(fullname) + HDstrlen(base_name) + 1) < size) { diff --git a/perform/sio_engine.c b/perform/sio_engine.c index 8539f75..4ce3aa0 100644 --- a/perform/sio_engine.c +++ b/perform/sio_engine.c @@ -371,7 +371,8 @@ sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si fullname[i] = subdir[j]; } else { /* We didn't append the prefix yet */ - HDstrncpy(fullname, prefix, MIN(HDstrlen(prefix), size)); + HDstrncpy(fullname, prefix, size); + fullname[size - 1] = '\0'; } if ((HDstrlen(fullname) + HDstrlen(base_name) + 1) < size) { diff --git a/src/H5HGdbg.c b/src/H5HGdbg.c index 74044cb..16d8c49 100644 --- a/src/H5HGdbg.c +++ b/src/H5HGdbg.c @@ -91,9 +91,8 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, unsigned u, nused, maxobj; unsigned j, k; H5HG_heap_t *h = NULL; - char buf[64]; uint8_t *p = NULL; - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -107,66 +106,69 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, if(NULL == (h = H5HG_protect(f, dxpl_id, addr, H5AC_READ))) HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect global heap collection"); - fprintf(stream, "%*sGlobal Heap Collection...\n", indent, ""); - fprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, + HDfprintf(stream, "%*sGlobal Heap Collection...\n", indent, ""); + HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Dirty:", (int)(h->cache_info.is_dirty)); - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, "Total collection size in file:", (unsigned long)(h->size)); - for (u=1, nused=0, maxobj=0; u<h->nused; u++) { - if (h->obj[u].begin) { + for(u = 1, nused = 0, maxobj = 0; u < h->nused; u++) + if(h->obj[u].begin) { nused++; - if (u>maxobj) maxobj = u; + if (u>maxobj) + maxobj = u; } - } - fprintf (stream, "%*s%-*s %u/%lu/", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %u/%lu/", indent, "", fwidth, "Objects defined/allocated/max:", - nused, (unsigned long)h->nalloc); + nused, + (unsigned long)h->nalloc); if(nused) - fprintf(stream, "%u\n", maxobj); + HDfprintf(stream, "%u\n", maxobj); else - fprintf(stream, "NA\n"); + HDfprintf(stream, "NA\n"); - fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, "Free space:", (unsigned long)(h->obj[0].size)); - for (u=1; u<h->nused; u++) { - if (h->obj[u].begin) { - sprintf (buf, "Object %u", u); - fprintf (stream, "%*s%s\n", indent, "", buf); - fprintf (stream, "%*s%-*s %lu\n", indent+3, "", MIN(fwidth-3, 0), + for(u = 1; u < h->nused; u++) + if(h->obj[u].begin) { + char buf[64]; + + HDsnprintf(buf, sizeof(buf), "Object %u", u); + HDfprintf(stream, "%*s%s\n", indent, "", buf); + HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MIN(fwidth - 3, 0), "Obffset in block:", (unsigned long)(h->obj[u].begin - h->chunk)); - fprintf (stream, "%*s%-*s %d\n", indent+3, "", MIN(fwidth-3, 0), + HDfprintf(stream, "%*s%-*s %d\n", indent + 3, "", MIN(fwidth - 3, 0), "Reference count:", h->obj[u].nrefs); - fprintf (stream, "%*s%-*s %lu/%lu\n", indent+3, "", - MIN(fwidth-3, 0), + HDfprintf(stream, "%*s%-*s %lu/%lu\n", indent + 3, "", + MIN(fwidth - 3, 0), "Size of object body:", (unsigned long)(h->obj[u].size), (unsigned long)H5HG_ALIGN(h->obj[u].size)); - p = h->obj[u].begin + H5HG_SIZEOF_OBJHDR (f); - for (j=0; j<h->obj[u].size; j+=16) { - fprintf (stream, "%*s%04u: ", indent+6, "", j); - for (k=0; k<16; k++) { - if (8==k) fprintf (stream, " "); - if (j+k<h->obj[u].size) { - fprintf (stream, "%02x ", p[j+k]); - } else { + p = h->obj[u].begin + H5HG_SIZEOF_OBJHDR(f); + for(j = 0; j < h->obj[u].size; j += 16) { + HDfprintf(stream, "%*s%04u: ", indent + 6, "", j); + for(k = 0; k < 16; k++) { + if(8 == k) + HDfprintf(stream, " "); + if(j + k < h->obj[u].size) + HDfprintf(stream, "%02x ", p[j + k]); + else HDfputs(" ", stream); - } } - for (k=0; k<16 && j+k<h->obj[u].size; k++) { - if (8==k) fprintf (stream, " "); - HDfputc(p[j+k]>' ' && p[j+k]<='~' ? p[j+k] : '.', stream); + for(k = 0; k < 16 && j + k < h->obj[u].size; k++) { + if(8 == k) + HDfprintf(stream, " "); + HDfputc(p[j + k]>' ' && p[j + k] <= '~' ? p[j + k] : '.', stream); } - fprintf (stream, "\n"); + HDfprintf(stream, "\n"); } } - } done: if (h && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, addr, h, H5AC__NO_FLAGS_SET) < 0) diff --git a/src/H5HLdbg.c b/src/H5HLdbg.c index 29d5c82..4ac22b8 100644 --- a/src/H5HLdbg.c +++ b/src/H5HLdbg.c @@ -54,8 +54,8 @@ herr_t H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int fwidth) { H5HL_t *h = NULL; - int i, overlap, free_block; - H5HL_free_t *freelist = NULL; + int free_block; + H5HL_free_t *freelist; uint8_t *marker = NULL; size_t amount_free = 0; herr_t ret_value = SUCCEED; /* Return value */ @@ -72,8 +72,8 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int if(NULL == (h = (H5HL_t *)H5HL_protect(f, dxpl_id, addr, H5AC_READ))) HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap") - fprintf(stream, "%*sLocal Heap...\n", indent, ""); - fprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + HDfprintf(stream, "%*sLocal Heap...\n", indent, ""); + HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, "Header size (in bytes):", (unsigned long)h->prfx_size); HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, @@ -90,34 +90,36 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int if(NULL == (marker = (uint8_t *)H5MM_calloc(h->dblk_size))) HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed") - fprintf(stream, "%*sFree Blocks (offset, size):\n", indent, ""); - + HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, ""); for(free_block = 0, freelist = h->freelist; freelist; freelist = freelist->next, free_block++) { char temp_str[32]; - sprintf(temp_str,"Block #%d:",free_block); + HDsnprintf(temp_str, sizeof(temp_str), "Block #%d:", free_block); HDfprintf(stream, "%*s%-*s %8Zu, %8Zu\n", indent+3, "", MAX(0,fwidth-9), temp_str, freelist->offset, freelist->size); if((freelist->offset + freelist->size) > h->dblk_size) - fprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n"); + HDfprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n"); else { - for(i = overlap = 0; i < (int)(freelist->size); i++) { + int overlap = 0; + size_t i; + + for(i = 0; i < freelist->size; i++) { if(marker[freelist->offset + i]) overlap++; marker[freelist->offset + i] = 1; } /* end for */ if(overlap) - fprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n"); + HDfprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n"); else amount_free += freelist->size; } /* end for */ } /* end for */ if(h->dblk_size) - fprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth, "Percent of heap used:", - (100.0 * (double)(h->dblk_size - amount_free) / (double)h->dblk_size)); + ((double)100.0f * (double)(h->dblk_size - amount_free) / (double)h->dblk_size)); /* * Print the data in a VMS-style octal dump. diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 69cc157..9d1fe48 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -208,6 +208,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, char *parent_group_name = NULL;/* Temporary pointer to group name */ char local_group_name[H5L_EXT_TRAVERSE_BUF_SIZE]; /* Local buffer to hold group name */ char *temp_file_name = NULL; /* Temporary pointer to file name */ + size_t temp_file_name_len; /* Length of temporary file name */ char *actual_file_name = NULL; /* Parent file's actual name */ H5P_genplist_t *fa_plist; /* File access property list pointer */ H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */ @@ -312,6 +313,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, /* Copy the file name to use */ if(NULL == (temp_file_name = H5MM_strdup(file_name))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + temp_file_name_len = HDstrlen(temp_file_name); /* target file_name is an absolute pathname: see RM for detailed description */ if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) { @@ -329,7 +331,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, ptr++; /* Copy into the temp. file name */ - HDstrncpy(temp_file_name, ptr, HDstrlen(ptr) + 1); + HDstrncpy(temp_file_name, ptr, temp_file_name_len); + temp_file_name[temp_file_name_len - 1] = '\0'; } /* end if */ } /* end if */ else if(H5_CHECK_ABS_DRIVE(file_name)) { @@ -339,7 +342,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, H5E_clear_stack(NULL); /* strip "<drive-letter>:" */ - HDstrncpy(temp_file_name, &file_name[2], (HDstrlen(file_name) - 2) + 1); + HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len); + temp_file_name[temp_file_name_len - 1] = '\0'; } /* end if */ } /* end if */ @@ -579,9 +583,9 @@ H5Lcreate_external(const char *file_name, const char *obj_name, /* Encode the external link information */ p = (uint8_t *)ext_link_buf; *p++ = (H5L_EXT_VERSION << 4) | H5L_EXT_FLAGS_ALL; /* External link version & flags */ - HDstrncpy((char *)p, file_name, file_name_len); /* Name of file containing external link's object */ + HDstrncpy((char *)p, file_name, buf_size - 1); /* Name of file containing external link's object */ p += file_name_len; - HDstrncpy((char *)p, norm_obj_name, norm_obj_name_len); /* External link's object */ + HDstrncpy((char *)p, norm_obj_name, buf_size - (file_name_len + 1)); /* External link's object */ /* Create an external link */ if(H5L_create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, H5AC_dxpl_id) < 0) diff --git a/src/H5Oattr.c b/src/H5Oattr.c index b8e6b32..2269bd3 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -793,7 +793,7 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in { const H5A_t *mesg = (const H5A_t *)_mesg; const char *s; /* Temporary string pointer */ - char buf[256]; /* Temporary string buffer */ + char buf[128]; /* Temporary string buffer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -804,7 +804,7 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in HDassert(indent >= 0); HDassert(fwidth >= 0); - fprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth, "Name:", mesg->shared->name); switch(mesg->shared->encoding) { @@ -830,17 +830,17 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in case H5T_CSET_RESERVED_13: case H5T_CSET_RESERVED_14: case H5T_CSET_RESERVED_15: - sprintf(buf, "H5T_CSET_RESERVED_%d", (int)(mesg->shared->encoding)); + HDsnprintf(buf, sizeof(buf), "H5T_CSET_RESERVED_%d", (int)(mesg->shared->encoding)); s = buf; break; case H5T_CSET_ERROR: default: - sprintf(buf, "Unknown character set: %d", (int)(mesg->shared->encoding)); + HDsnprintf(buf, sizeof(buf), "Unknown character set: %d", (int)(mesg->shared->encoding)); s = buf; break; } /* end switch */ - fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Character Set of Name:", s); HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth, @@ -856,18 +856,18 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in "Creation Index:", (unsigned)mesg->shared->crt_idx); - fprintf(stream, "%*sDatatype...\n", indent, ""); - fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0,fwidth-3), + HDfprintf(stream, "%*sDatatype...\n", indent, ""); + HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0,fwidth - 3), "Encoded Size:", (unsigned long)(mesg->shared->dt_size)); if((H5O_MSG_DTYPE->debug)(f, dxpl_id, mesg->shared->dt, stream, indent + 3, MAX(0, fwidth - 3)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to display datatype message info") - fprintf(stream, "%*sDataspace...\n", indent, ""); - fprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX(0, fwidth - 3), + HDfprintf(stream, "%*sDataspace...\n", indent, ""); + HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MAX(0, fwidth - 3), "Encoded Size:", (unsigned long)(mesg->shared->ds_size)); - if(H5S_debug(f, dxpl_id, mesg->shared->ds, stream, indent+3, MAX(0, fwidth - 3)) < 0) + if(H5S_debug(f, dxpl_id, mesg->shared->ds, stream, indent + 3, MAX(0, fwidth - 3)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, "unable to display dataspace message info") done: diff --git a/src/H5Oefl.c b/src/H5Oefl.c index 1297780..bbc7e92 100644 --- a/src/H5Oefl.c +++ b/src/H5Oefl.c @@ -545,7 +545,6 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s int indent, int fwidth) { const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg; - char buf[64]; size_t u; FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -565,8 +564,10 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s mesg->nused, mesg->nalloc); for(u = 0; u < mesg->nused; u++) { - sprintf (buf, "File %u", (unsigned)u); - HDfprintf (stream, "%*s%s:\n", indent, "", buf); + char buf[64]; + + HDsnprintf(buf, sizeof(buf), "File %u", (unsigned)u); + HDfprintf(stream, "%*s%s:\n", indent, "", buf); HDfprintf(stream, "%*s%-*s \"%s\"\n", indent+3, "", MAX (fwidth-3, 0), "Name:", @@ -576,11 +577,11 @@ H5O_efl_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * s "Name offset:", (unsigned long)(mesg->slot[u].name_offset)); - HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), + HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Offset of data in file:", (unsigned long)(mesg->slot[u].offset)); - HDfprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), + HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Bytes reserved for data:", (unsigned long)(mesg->slot[u].size)); } /* end for */ diff --git a/src/H5system.c b/src/H5system.c index 4280066..437a004 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -200,20 +200,28 @@ HDfprintf(FILE *stream, const char *fmt, ...) case 'H': if(sizeof(hsize_t) < sizeof(long)) modifier[0] = '\0'; - else if(sizeof(hsize_t) == sizeof(long)) - HDstrncpy(modifier, "l", 2); - else - HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, HDstrlen(H5_PRINTF_LL_WIDTH) + 1); + else if(sizeof(hsize_t) == sizeof(long)) { + HDstrncpy(modifier, "l", sizeof(modifier)); + modifier[sizeof(modifier) - 1] = '\0'; + } /* end if */ + else { + HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, sizeof(modifier)); + modifier[sizeof(modifier) - 1] = '\0'; + } /* end else */ break; case 'Z': case 'z': if(sizeof(size_t) < sizeof(long)) modifier[0] = '\0'; - else if(sizeof(size_t) == sizeof(long)) - HDstrncpy(modifier, "l", 2); - else - HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, HDstrlen(H5_PRINTF_LL_WIDTH) + 1); + else if(sizeof(size_t) == sizeof(long)) { + HDstrncpy(modifier, "l", sizeof(modifier)); + modifier[sizeof(modifier) - 1] = '\0'; + } /* end if */ + else { + HDstrncpy(modifier, H5_PRINTF_LL_WIDTH, sizeof(modifier)); + modifier[sizeof(modifier) - 1] = '\0'; + } /* end else */ break; default: diff --git a/test/h5test.c b/test/h5test.c index 32d78bd..b9da3c6 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -379,7 +379,7 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) /* Prepend the prefix value to the base name */ if (prefix && *prefix) { - if (isppdriver){ + if (isppdriver) { /* This is a parallel system */ char *subdir; @@ -406,9 +406,11 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) } } - if (!fullname[0]) + if (!fullname[0]) { /* We didn't append the prefix yet */ - HDstrncpy(fullname, prefix, MIN(HDstrlen(prefix), size)); + HDstrncpy(fullname, prefix, size); + fullname[size -1] = '\0'; + } if (HDstrlen(fullname) + HDstrlen(base_name) + 1 < size) { /* diff --git a/tools/h5dump/h5dump_xml.c b/tools/h5dump/h5dump_xml.c index 03e1254..b94879c 100644 --- a/tools/h5dump/h5dump_xml.c +++ b/tools/h5dump/h5dump_xml.c @@ -644,6 +644,7 @@ xml_escape_the_name(const char *str) const char *cp; char *ncp; char *rcp; + size_t ncp_len; if (!str) return NULL; @@ -653,21 +654,16 @@ xml_escape_the_name(const char *str) extra = 0; for (i = 0; i < len; i++) { - if (*cp == '\"') { + if (*cp == '\"') extra += (HDstrlen(quote) - 1); - } - else if (*cp == '\'') { + else if (*cp == '\'') extra += (HDstrlen(apos) - 1); - } - else if (*cp == '<') { + else if (*cp == '<') extra += (HDstrlen(lt) - 1); - } - else if (*cp == '>') { + else if (*cp == '>') extra += (HDstrlen(gt) - 1); - } - else if (*cp == '&') { + else if (*cp == '&') extra += (HDstrlen(amp) - 1); - } cp++; } @@ -676,40 +672,43 @@ xml_escape_the_name(const char *str) return HDstrdup(str); cp = str; - rcp = ncp = (char *)HDmalloc(len + extra + 1); + ncp_len = len + extra + 1; + rcp = ncp = (char *)HDmalloc(ncp_len); if (!ncp) return NULL; /* ?? */ for (i = 0; i < len; i++) { + size_t esc_len; + + HDassert(ncp_len); if (*cp == '\'') { - HDstrncpy(ncp, apos, HDstrlen(apos)); - ncp += HDstrlen(apos); - cp++; + HDstrncpy(ncp, apos, ncp_len); + esc_len = HDstrlen(apos); } else if (*cp == '<') { - HDstrncpy(ncp, lt, HDstrlen(lt)); - ncp += HDstrlen(lt); - cp++; + HDstrncpy(ncp, lt, ncp_len); + esc_len = HDstrlen(lt); } else if (*cp == '>') { - HDstrncpy(ncp, gt, HDstrlen(gt)); - ncp += HDstrlen(gt); - cp++; + HDstrncpy(ncp, gt, ncp_len); + esc_len = HDstrlen(gt); } else if (*cp == '\"') { - HDstrncpy(ncp, quote, HDstrlen(quote)); - ncp += HDstrlen(quote); - cp++; + HDstrncpy(ncp, quote, ncp_len); + esc_len = HDstrlen(quote); } else if (*cp == '&') { - HDstrncpy(ncp, amp, HDstrlen(amp)); - ncp += HDstrlen(amp); - cp++; + HDstrncpy(ncp, amp, ncp_len); + esc_len = HDstrlen(amp); } else { - *ncp++ = *cp++; + *ncp = *cp; + esc_len = 1; } + ncp += esc_len; + ncp_len -= esc_len; + cp++; } *ncp = '\0'; @@ -739,6 +738,7 @@ xml_escape_the_string(const char *str, int slen) const char *cp; char *ncp; char *rcp; + size_t ncp_len; if (!str) return NULL; @@ -753,65 +753,65 @@ xml_escape_the_string(const char *str, int slen) extra = 0; for (i = 0; i < len; i++) { - if (*cp == '\\') { + if (*cp == '\\') extra++; - } - else if (*cp == '\"') { + else if (*cp == '\"') extra++; - } - else if (*cp == '\'') { + else if (*cp == '\'') extra += (HDstrlen(apos) - 1); - } - else if (*cp == '<') { + else if (*cp == '<') extra += (HDstrlen(lt) - 1); - } - else if (*cp == '>') { + else if (*cp == '>') extra += (HDstrlen(gt) - 1); - } - else if (*cp == '&') { + else if (*cp == '&') extra += (HDstrlen(amp) - 1); - } cp++; } cp = str; - rcp = ncp = (char *) HDcalloc((len + extra + 1), sizeof(char)); + ncp_len = len + extra + 1; + rcp = ncp = (char *) HDcalloc(ncp_len, sizeof(char)); if (ncp == NULL) return NULL; /* ?? */ for (i = 0; i < len; i++) { + size_t esc_len; + + HDassert(ncp_len); if (*cp == '\\') { *ncp++ = '\\'; - *ncp++ = *cp++; + *ncp = *cp; + esc_len = 1; } else if (*cp == '\"') { *ncp++ = '\\'; - *ncp++ = *cp++; + *ncp = *cp; + esc_len = 1; } else if (*cp == '\'') { - HDstrncpy(ncp, apos, HDstrlen(apos)); - ncp += HDstrlen(apos); - cp++; + HDstrncpy(ncp, apos, ncp_len); + esc_len = HDstrlen(apos); } else if (*cp == '<') { - HDstrncpy(ncp, lt, HDstrlen(lt)); - ncp += HDstrlen(lt); - cp++; + HDstrncpy(ncp, lt, ncp_len); + esc_len = HDstrlen(lt); } else if (*cp == '>') { - HDstrncpy(ncp, gt, HDstrlen(gt)); - ncp += HDstrlen(gt); - cp++; + HDstrncpy(ncp, gt, ncp_len); + esc_len = HDstrlen(gt); } else if (*cp == '&') { - HDstrncpy(ncp, amp, HDstrlen(amp)); - ncp += HDstrlen(amp); - cp++; + HDstrncpy(ncp, amp, ncp_len); + esc_len = HDstrlen(amp); } else { - *ncp++ = *cp++; + *ncp = *cp; + esc_len = 1; } + ncp += esc_len; + ncp_len -= esc_len; + cp++; } *ncp = '\0'; diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index a475ded..fca3096 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -49,7 +49,9 @@ typedef struct { } trav_print_udata_t; /* format for hsize_t */ +#ifdef H5TRAV_PRINT_SPACE #define HSIZE_T_FORMAT "%" H5_PRINTF_LL_WIDTH "u" +#endif /* H5TRAV_PRINT_SPACE */ /*------------------------------------------------------------------------- * local functions @@ -680,11 +682,11 @@ h5trav_getindext(const char *name, const trav_table_t *table) for(i = 0; i < table->nobjs; i++) { /* Check for object name having full path (with leading '/') */ if(HDstrcmp(name, table->objs[i].name) == 0) - return(i); + return((int)i); /* Check for object name without leading '/' */ if(HDstrcmp(name, table->objs[i].name + 1) == 0) - return(i); + return((int)i); /* search also in the list of links */ if(table->objs[i].nlinks) { @@ -693,11 +695,11 @@ h5trav_getindext(const char *name, const trav_table_t *table) for ( j=0; j<table->objs[i].nlinks; j++) { /* Check for object name having full path (with leading '/') */ if(HDstrcmp(name, table->objs[i].links[j].new_name) == 0) - return(i); + return((int)i); /* Check for object name without leading '/' */ if(HDstrcmp(name, table->objs[i].links[j].new_name + 1) == 0) - return(i); + return((int)i); } /* end for */ } /* end if */ } /* end for */ @@ -807,7 +809,7 @@ void trav_table_addflags(unsigned *flags, h5trav_type_t type, trav_table_t *table) { - unsigned int new_obj; + size_t new_obj; if(table->nobjs == table->size) { table->size = MAX(1, table->size * 2); @@ -995,6 +997,8 @@ trav_print_visit_obj(const char *path, const H5O_info_t *oinfo, printf(" %-10s %s", "datatype", path); break; + case H5O_TYPE_UNKNOWN: + case H5O_TYPE_NTYPES: default: printf(" %-10s %s", "unknown object type", path); break; @@ -1005,7 +1009,7 @@ trav_print_visit_obj(const char *path, const H5O_info_t *oinfo, /* Finish printing line about object */ printf("\n"); if(trav_verbosity > 0) - H5Aiterate_by_name(print_udata->fid, path, trav_index_by, trav_index_order, NULL, trav_attr, path, H5P_DEFAULT); + H5Aiterate_by_name(print_udata->fid, path, trav_index_by, trav_index_order, NULL, trav_attr, (void *)path, H5P_DEFAULT); } else /* Print the link's original name */ @@ -1040,7 +1044,8 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata) char *targbuf = (char*)HDmalloc(linfo->u.val_size + 1); HDassert(targbuf); - H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT); + if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0) + targbuf[0] = 0; printf(" %-10s %s -> %s\n", "link", path, targbuf); HDfree(targbuf); } /* end if */ @@ -1051,21 +1056,28 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata) case H5L_TYPE_EXTERNAL: if(linfo->u.val_size > 0) { char *targbuf; - const char *filename; - const char *objname; + const char *filename = NULL; + const char *objname = NULL; targbuf = (char*)HDmalloc(linfo->u.val_size + 1); HDassert(targbuf); - H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT); - H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname); - printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname); + if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0) + targbuf[0] = 0; + if(H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) >= 0) + printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname); HDfree(targbuf); } /* end if */ else printf(" %-10s %s ->\n", "ext link", path); break; + case H5L_TYPE_HARD: + /* Should be handled elsewhere */ + return(-1); + + case H5L_TYPE_ERROR: + case H5L_TYPE_MAX: default: printf(" %-10s %s -> ???\n", "unknown type of UD link", path); break; diff --git a/tools/misc/h5debug.c b/tools/misc/h5debug.c index e8de44c..6b043ba 100644 --- a/tools/misc/h5debug.c +++ b/tools/misc/h5debug.c @@ -175,7 +175,10 @@ main(int argc, char *argv[]) HDexit(1); } /* end if */ if(HDstrchr(argv[1], '%')) - H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT); + if(H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT) < 0) { + fprintf(stderr, "cannot set file access property list\n"); + HDexit(1); + } if((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0) { HDfprintf(stderr, "cannot open file\n"); HDexit(1); |