summaryrefslogtreecommitdiffstats
path: root/tools/h5ls
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-03-20 03:44:28 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-03-20 03:44:28 (GMT)
commit59dd5665a5887efa8e91e0339719e4bd0c2be2a6 (patch)
treef00ce45d9f64ae1c06d043947fb6d65900160d26 /tools/h5ls
parent8ad18f496ad665faffc4f2fd0eae8140b53ab760 (diff)
downloadhdf5-59dd5665a5887efa8e91e0339719e4bd0c2be2a6.zip
hdf5-59dd5665a5887efa8e91e0339719e4bd0c2be2a6.tar.gz
hdf5-59dd5665a5887efa8e91e0339719e4bd0c2be2a6.tar.bz2
[svn-r23395] Description:
Bring Coverity changes from branch to trunk: r20682: fixed coverity: 76, 77, 635, 636, 1164, 1165, 1166, 1121, 1122, 1117, 1343 Tested on: Mac OSX/64 10.8.3 (amazon) w/C++ & FORTRAN (too minor to require h5committest)
Diffstat (limited to 'tools/h5ls')
-rw-r--r--tools/h5ls/h5ls.c247
1 files changed, 141 insertions, 106 deletions
diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c
index 7135e4e..832d91f 100644
--- a/tools/h5ls/h5ls.c
+++ b/tools/h5ls/h5ls.c
@@ -115,8 +115,8 @@ typedef struct {
hid_t gid; /* Group ID */
hbool_t symlink_target; /* Whether this is the target of an symbolic link */
symlink_trav_t *symlink_list; /* List of visited symbolic links */
- int base_len; /* Length of base path name, if not root */
- int name_start; /* # of leading characters to strip off path names on output */
+ size_t base_len; /* Length of base path name, if not root */
+ size_t name_start; /* # of leading characters to strip off path names on output */
}iter_t;
/* Command-line switches */
@@ -154,7 +154,6 @@ static struct dispatch_t {
dispatch_g[TYPE].list2 = (LIST2); \
}
-static void display_type(hid_t type, int ind);
static void print_type(h5tools_str_t *buffer, hid_t type, int ind);
static herr_t visit_obj(hid_t file, const char *oname, iter_t *iter);
@@ -342,7 +341,7 @@ print_obj_name(h5tools_str_t *buffer, const iter_t *iter, const char *oname,
int n;
if(show_file_name_g)
- sprintf(fullname, "%s/%s", iter->fname, oname + iter->name_start);
+ HDsnprintf(fullname, sizeof(fullname), "%s/%s", iter->fname, oname + iter->name_start);
else
name = oname + iter->name_start;
@@ -553,14 +552,14 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind)
/* If the precision is less than the total size then show the precision
* and offset on the following line. Also display the padding
* information. */
- if (8*H5Tget_size(type)!=(prec=H5Tget_precision(type))) {
+ if(8 * H5Tget_size(type) != (prec = H5Tget_precision(type))) {
h5tools_str_append(buffer, "\n%*s(%lu bit%s of precision beginning at bit %lu)",
- ind, "", (unsigned long)prec, 1==prec?"":"s",
+ ind, "", (unsigned long)prec, 1 == prec ? "" : "s",
(unsigned long)H5Tget_offset(type));
H5Tget_pad(type, &plsb, &pmsb);
- if (H5Tget_offset(type)>0) {
- switch (plsb) {
+ if(H5Tget_offset(type) > 0) {
+ switch(plsb) {
case H5T_PAD_ZERO:
plsb_s = "zero";
break;
@@ -575,12 +574,11 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind)
plsb_s = "unknown";
break;
default:
- ;
break;
}
}
- if (H5Tget_offset(type)+prec<8*H5Tget_size(type)) {
- switch (pmsb) {
+ if((unsigned)H5Tget_offset(type) + prec < 8 * H5Tget_size(type)) {
+ switch(pmsb) {
case H5T_PAD_ZERO:
pmsb_s = "zero";
break;
@@ -595,23 +593,22 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind)
pmsb_s = "unknown";
break;
default:
- ;
break;
}
}
if (plsb_s || pmsb_s) {
h5tools_str_append(buffer, "\n%*s(", ind, "");
if (plsb_s) {
- nbits = H5Tget_offset(type);
+ nbits = (unsigned)H5Tget_offset(type);
h5tools_str_append(buffer, "%lu %s bit%s at bit 0",
- (unsigned long)nbits, plsb_s, 1==nbits?"":"s");
+ (unsigned long)nbits, plsb_s, 1 == nbits ? "" : "s");
}
if (plsb_s && pmsb_s) h5tools_str_append(buffer, ", ");
if (pmsb_s) {
- nbits = 8*H5Tget_size(type)-(H5Tget_offset(type)+prec);
+ nbits = (8 * H5Tget_size(type)) - ((unsigned)H5Tget_offset(type) + prec);
h5tools_str_append(buffer, "%lu %s bit%s at bit %lu",
- (unsigned long)nbits, pmsb_s, 1==nbits?"":"s",
- (unsigned long)(8*H5Tget_size(type)-nbits));
+ (unsigned long)nbits, pmsb_s, 1 == nbits ? "" : "s",
+ (unsigned long)(8 * H5Tget_size(type) - nbits));
}
h5tools_str_append(buffer, ")");
}
@@ -829,14 +826,18 @@ print_cmpd_type(h5tools_str_t *buffer, hid_t type, int ind)
char *name=NULL; /* member name */
size_t size; /* total size of type in bytes */
hid_t subtype; /* member data type */
- unsigned nmembs; /* number of members */
+ int nmembs; /* number of members */
int n; /* miscellaneous counters */
unsigned i; /* miscellaneous counters */
- if (H5T_COMPOUND!=H5Tget_class(type)) return FALSE;
+ if(H5T_COMPOUND != H5Tget_class(type))
+ return FALSE;
+ nmembs = H5Tget_nmembers(type);
+ if(nmembs <= 0)
+ return FALSE;
+
h5tools_str_append(buffer, "struct {");
- nmembs=H5Tget_nmembers(type);
- for (i=0; i<nmembs; i++) {
+ for(i = 0; i < (unsigned)nmembs; i++) {
/* Name and offset */
name = H5Tget_member_name(type, i);
@@ -877,89 +878,109 @@ print_cmpd_type(h5tools_str_t *buffer, hid_t type, int ind)
static hbool_t
print_enum_type(h5tools_str_t *buffer, hid_t type, int ind)
{
- char **name=NULL; /* member names */
- unsigned char *value=NULL; /* value array */
- unsigned char *copy = NULL; /* a pointer to value array */
- unsigned nmembs; /* number of members */
- int nchars; /* number of output characters */
+ int nmembs; /* number of members */
hid_t super; /* enum base integer type */
- hid_t native=-1; /* native integer data type */
- size_t dst_size; /* destination value type size */
- unsigned i; /* miscellaneous counters */
- size_t j;
- if (H5T_ENUM!=H5Tget_class(type)) return FALSE;
+ if(H5T_ENUM != H5Tget_class(type))
+ return FALSE;
nmembs = H5Tget_nmembers(type);
- HDassert(nmembs>0);
+ if(nmembs < 0)
+ return FALSE;
+
super = H5Tget_super(type);
h5tools_str_append(buffer, "enum ");
- print_type(buffer, super, ind+4);
+ print_type(buffer, super, ind + 4);
h5tools_str_append(buffer, " {");
- /* Determine what data type to use for the native values. To simplify
- * things we entertain three possibilities:
- * 1. long long -- the largest native signed integer
- * 2. unsigned long long -- the largest native unsigned integer
- * 3. raw format */
- if (H5Tget_size(type)<=sizeof(long long)) {
- dst_size = sizeof(long long);
- if (H5T_SGN_NONE==H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
+ if(nmembs > 0) {
+ char **name; /* member names */
+ unsigned char *value; /* value array */
+ hid_t native = -1; /* native integer data type */
+ size_t dst_size; /* destination value type size */
+ unsigned i; /* miscellaneous counters */
+
+ /* Determine what data type to use for the native values. To simplify
+ * things we entertain three possibilities:
+ * 1. long long -- the largest native signed integer
+ * 2. unsigned long long -- the largest native unsigned integer
+ * 3. raw format */
+ if(H5Tget_size(type) <= sizeof(long long)) {
+ dst_size = sizeof(long long);
+ if(H5T_SGN_NONE == H5Tget_sign(type))
+ native = H5T_NATIVE_ULLONG;
+ else
+ native = H5T_NATIVE_LLONG;
+ } /* end if */
+ else
+ dst_size = H5Tget_size(type);
+
+ /* Get the names and raw values of all members */
+ name = (char **)HDcalloc((size_t)nmembs, sizeof(char *));
+ value = (unsigned char *)HDcalloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
+ for(i = 0; i < (unsigned)nmembs; i++) {
+ name[i] = H5Tget_member_name(type, i);
+ H5Tget_member_value(type, i, value + i * H5Tget_size(type));
}
- } else {
- dst_size = H5Tget_size(type);
- }
-
- /* Get the names and raw values of all members */
- name = HDcalloc(nmembs, sizeof(char*));
- value = (unsigned char *)HDcalloc(nmembs, MAX(H5Tget_size(type), dst_size));
- for (i=0; i<nmembs; i++) {
- name[i] = H5Tget_member_name(type, i);
- H5Tget_member_value(type, i, value+i*H5Tget_size(type));
- }
- /* Convert values to native data type */
- if (native>0) H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT);
+ /* Convert values to native data type */
+ if(native > 0)
+ if(H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT) < 0) {
+ /* Release resources */
+ for(i = 0; i < (unsigned)nmembs; i++)
+ HDfree(name[i]);
+ HDfree(name);
+ HDfree(value);
- /* Sort members by increasing value */
- /*not implemented yet*/
-
- /* Print members */
- for (i=0; i<nmembs; i++) {
- h5tools_str_append(buffer, "\n%*s", ind+4, "");
- nchars = print_string(buffer, name[i], TRUE);
- h5tools_str_append(buffer, "%*s = ", MAX(0, 16-nchars), "");
+ return FALSE;
+ }
- if (native<0) {
- h5tools_str_append(buffer, "0x");
- for (j=0; j<dst_size; j++)
- h5tools_str_append(buffer, "%02x", value[i*dst_size+j]);
- }
- else if (H5T_SGN_NONE==H5Tget_sign(native)) {
- /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
- *strangely, unless use another pointer "copy".*/
- copy = value+i*dst_size;
- h5tools_str_append(buffer, HSIZE_T_FORMAT, *((unsigned long long*)((void*)copy)));
- }
- else {
- /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
- *strangely, unless use another pointer "copy".*/
- copy = value+i*dst_size;
- h5tools_str_append(buffer, "%"H5_PRINTF_LL_WIDTH"d",
- *((long long*)((void*)copy)));
+ /* Sort members by increasing value */
+ /*not implemented yet*/
+
+ /* Print members */
+ for(i = 0; i < (unsigned)nmembs; i++) {
+ unsigned char *copy; /* a pointer to value array */
+ int nchars; /* number of output characters */
+
+ h5tools_str_append(buffer, "\n%*s", ind+4, "");
+ nchars = print_string(buffer, name[i], TRUE);
+ h5tools_str_append(buffer, "%*s = ", MAX(0, 16 - nchars), "");
+
+ if(native < 0) {
+ size_t j;
+
+ h5tools_str_append(buffer, "0x");
+ for(j = 0; j < dst_size; j++)
+ h5tools_str_append(buffer, "%02x", value[i*dst_size+j]);
+ }
+ else if(H5T_SGN_NONE == H5Tget_sign(native)) {
+ /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
+ *strangely, unless use another pointer "copy".*/
+ copy = value + i * dst_size;
+ h5tools_str_append(buffer, HSIZE_T_FORMAT, *((unsigned long long*)((void*)copy)));
+ }
+ else {
+ /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
+ *strangely, unless use another pointer "copy".*/
+ copy = value + i * dst_size;
+ h5tools_str_append(buffer, "%"H5_PRINTF_LL_WIDTH"d",
+ *((long long*)((void*)copy)));
+ }
}
+
+ /* Release resources */
+ for(i = 0; i < (unsigned)nmembs; i++)
+ HDfree(name[i]);
+ HDfree(name);
+ HDfree(value);
}
+ else
+ h5tools_str_append(buffer, "\n%*s <empty>", ind+4, "");
+
+ h5tools_str_append(buffer, "\n%*s}", ind, "");
- /* Release resources */
- for (i=0; i<nmembs; i++) HDfree(name[i]);
- HDfree(name);
- HDfree(value);
H5Tclose(super);
- if (0==nmembs) h5tools_str_append(buffer, "\n%*s <empty>", ind+4, "");
- h5tools_str_append(buffer, "\n%*s}", ind, "");
return TRUE;
}
@@ -1189,10 +1210,11 @@ print_array_type(h5tools_str_t *buffer, hid_t type, int ind)
int ndims, i;
hsize_t *dims=NULL;
- if (H5T_ARRAY!=H5Tget_class(type)) return FALSE;
+ if (H5T_ARRAY!=H5Tget_class(type))
+ return FALSE;
ndims = H5Tget_array_ndims(type);
if (ndims) {
- dims = (hsize_t *)HDmalloc(ndims*sizeof(dims[0]));
+ dims = (hsize_t *)HDmalloc((unsigned)ndims * sizeof(dims[0]));
H5Tget_array_dims2(type, dims);
/* Print dimensions */
@@ -1202,9 +1224,8 @@ print_array_type(h5tools_str_t *buffer, hid_t type, int ind)
HDfree(dims);
}
- else {
+ else
h5tools_str_append(buffer, " [SCALAR]\n", rawoutstream);
- }
/* Print parent type */
@@ -1390,7 +1411,7 @@ dump_dataset_values(hid_t dset)
outputformat.line_per_line = 1;
}
else {
- outputformat.line_ncols = width_g;
+ outputformat.line_ncols = (unsigned)width_g;
}
if (label_g) outputformat.cmpd_name = "%s=";
outputformat.line_pre = " %s ";
@@ -1412,9 +1433,9 @@ dump_dataset_values(hid_t dset)
}
outputformat.arr_linebreak = 0;
/* Floating point types should display full precision */
- sprintf(fmt_float, "%%1.%dg", FLT_DIG);
+ HDsnprintf(fmt_float, sizeof(fmt_float), "%%1.%dg", FLT_DIG);
outputformat.fmt_float = fmt_float;
- sprintf(fmt_double, "%%1.%dg", DBL_DIG);
+ HDsnprintf(fmt_double, sizeof(fmt_double), "%%1.%dg", DBL_DIG);
outputformat.fmt_double = fmt_double;
if (hexdump_g) {
@@ -1428,8 +1449,7 @@ dump_dataset_values(hid_t dset)
outputformat.ascii = TRUE;
outputformat.elmt_suf1 = "";
outputformat.elmt_suf2 = "";
- strcpy(string_prefix, outputformat.line_pre);
- strcat(string_prefix, "\"");
+ HDsnprintf(string_prefix, sizeof(string_prefix), "%s\"", outputformat.line_pre);
outputformat.line_pre = string_prefix;
outputformat.line_suf = "\"";
}
@@ -1487,7 +1507,6 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo,
size_t need;
int ndims;
int i;
- int n;
void *buf;
H5S_class_t space_type;
hsize_t curr_pos = 0; /* total data element position */
@@ -1502,7 +1521,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo,
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, " Attribute: ");
- n = print_string(&buffer, attr_name, TRUE);
+ print_string(&buffer, attr_name, TRUE);
if((attr = H5Aopen(obj, attr_name, H5P_DEFAULT))) {
space = H5Aget_space(attr);
@@ -1535,6 +1554,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo,
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0);
break;
+ case H5S_NO_CLASS:
default:
/* Unknown dataspace type */
h5tools_str_append(&buffer, " unknown\n");
@@ -1570,7 +1590,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t UNUSED *ainfo,
outputformat.str_repeat = 8;
}
- outputformat.line_ncols = width_g;
+ outputformat.line_ncols = (unsigned)width_g;
if(label_g)
outputformat.cmpd_name = "%s=";
if(string_g && 1==H5Tget_size(type) &&
@@ -1777,7 +1797,7 @@ dataset_list2(hid_t dset, const char UNUSED *name)
}
/* Print total raw storage size */
- total = H5Sget_simple_extent_npoints(space) * H5Tget_size(type);
+ total = (hsize_t)H5Sget_simple_extent_npoints(space) * H5Tget_size(type);
used = H5Dget_storage_size(dset);
tclass = H5Tget_class(type);
h5tools_str_append(&buffer, " %-10s ", "Storage:");
@@ -1795,13 +1815,24 @@ dataset_list2(hid_t dset, const char UNUSED *name)
}
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_COMPOUND:
+ case H5T_ENUM:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
h5tools_str_append(&buffer, HSIZE_T_FORMAT" logical byte%s, "HSIZE_T_FORMAT" allocated byte%s",
total, 1==total?"":"s",
used, 1==used?"":"s");
if (used>0)
{
- utilization = (total*100.0)/used;
+ utilization = ((double)total * (double)100.0f) / (double)used;
h5tools_str_append(&buffer, ", %1.2f%% utilization", utilization);
}
}
@@ -1811,7 +1842,8 @@ dataset_list2(hid_t dset, const char UNUSED *name)
/* Print information about external strorage */
if((nf = H5Pget_external_count(dcpl)) > 0) {
for(i = 0, max_len = 0; i < nf; i++) {
- H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, NULL, NULL);
+ if(H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, NULL, NULL) < 0)
+ continue;
n = print_string(NULL, f_name, TRUE);
max_len = MAX(max_len, n);
} /* end for */
@@ -1857,7 +1889,7 @@ dataset_list2(hid_t dset, const char UNUSED *name)
filt_id = H5Pget_filter2(dcpl, (unsigned)i, &filt_flags, &cd_nelmts,
cd_values, sizeof(f_name), f_name, NULL);
f_name[sizeof(f_name) - 1] = '\0';
- sprintf(s, "Filter-%d:", i);
+ HDsnprintf(s, sizeof(s), "Filter-%d:", i);
h5tools_str_append(&buffer, " %-10s %s-%u %s {", s,
(f_name[0] ? f_name : "method"),
(unsigned)filt_id,
@@ -2054,7 +2086,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void
if (cmt_bufsize > 0) {
comment = (char *)HDmalloc((size_t)cmt_bufsize + 1); /* new_size including null terminator */
if(comment) {
- cmt_bufsize = H5Oget_comment(obj, comment, cmt_bufsize);
+ cmt_bufsize = H5Oget_comment(obj, comment, (size_t)cmt_bufsize);
if(cmt_bufsize > 0) {
comment[cmt_bufsize] = 0;
h5tools_str_reset(&buffer);
@@ -2267,6 +2299,9 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter)
}
break;
+ case H5L_TYPE_ERROR:
+ case H5L_TYPE_HARD:
+ case H5L_TYPE_MAX:
default:
h5tools_str_append(&buffer, "UD Link {cannot follow UD links}\n");
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, info->line_ncols, 0, 0);
@@ -2457,7 +2492,7 @@ get_width(void)
static hbool_t
is_valid_args(void)
{
- herr_t ret = TRUE;
+ hbool_t ret = TRUE;
if(recursive_g && grp_literal_g)
{