summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-04-25 16:59:51 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-04-25 16:59:51 (GMT)
commit65794c39bffdb5209849b016bde0b43166a73d7d (patch)
treefd5e55565a7b45a200dcac855035ab37bfffbb4e /tools
parent9f1262f9570b9e623f25f632d8730131897980ab (diff)
downloadhdf5-65794c39bffdb5209849b016bde0b43166a73d7d.zip
hdf5-65794c39bffdb5209849b016bde0b43166a73d7d.tar.gz
hdf5-65794c39bffdb5209849b016bde0b43166a73d7d.tar.bz2
[svn-r20626] Albert's test on bp reveals that the dumper had assertion failure when it tried to display empty attribute data. I added
a check for empty attribute in h5dump.c. I also added a check for empty dataset in tools/lib/h5tools.c. Tested on jam. But I tested the same changes in 1.8 on jam, linew, and amani.
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump.c76
-rw-r--r--tools/lib/h5tools.c8
2 files changed, 46 insertions, 38 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 7a3663f..64575c2 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2436,7 +2436,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index)
{
h5tool_format_t *outputformat = &dataformat;
int status = -1;
- void *buf;
+ void *buf = NULL;
hid_t space, type, p_type;
H5S_class_t space_type;
int ndims, i;
@@ -2586,45 +2586,49 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index)
alloc_size = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
- buf = malloc((size_t)alloc_size);
- assert(buf);
-
- if (H5Aread(obj_id, p_type, buf) >= 0)
- if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) {
- /*
- * Print 1-byte integer data as an ASCII character string
- * instead of integers if the `-r' or `--string' command-line
- * option was given.
- *
- * We don't want to modify the global dataformat, so make a
- * copy of it instead.
- */
- string_dataformat = *outputformat;
- string_dataformat.idx_fmt = " ";
- string_dataformat.line_multi_new = 1;
- string_dataformat.line_1st = " %s\"";
- string_dataformat.line_pre = " %s";
- string_dataformat.line_cont = " %s";
- string_dataformat.str_repeat = 8;
- string_dataformat.ascii = TRUE;
- string_dataformat.elmt_suf1 = "";
- string_dataformat.elmt_suf2 = "";
- string_dataformat.line_indent = "";
- strcpy(string_prefix, string_dataformat.line_pre);
- strcat(string_prefix, "\"");
- string_dataformat.line_pre = string_prefix;
- string_dataformat.line_suf = "\"";
- outputformat = &string_dataformat;
- }
+ if(alloc_size) {
+ buf = malloc((size_t)alloc_size);
+ assert(buf);
+
+ if (H5Aread(obj_id, p_type, buf) >= 0)
+ if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) {
+ /*
+ * Print 1-byte integer data as an ASCII character string
+ * instead of integers if the `-r' or `--string' command-line
+ * option was given.
+ *
+ * We don't want to modify the global dataformat, so make a
+ * copy of it instead.
+ */
+ string_dataformat = *outputformat;
+ string_dataformat.idx_fmt = " ";
+ string_dataformat.line_multi_new = 1;
+ string_dataformat.line_1st = " %s\"";
+ string_dataformat.line_pre = " %s";
+ string_dataformat.line_cont = " %s";
+ string_dataformat.str_repeat = 8;
+ string_dataformat.ascii = TRUE;
+ string_dataformat.elmt_suf1 = "";
+ string_dataformat.elmt_suf2 = "";
+ string_dataformat.line_indent = "";
+ strcpy(string_prefix, string_dataformat.line_pre);
+ strcat(string_prefix, "\"");
+ string_dataformat.line_pre = string_prefix;
+ string_dataformat.line_suf = "\"";
+ outputformat = &string_dataformat;
+ }
- status = h5tools_dump_mem(stdout, outputformat, obj_id, p_type,
+ status = h5tools_dump_mem(stdout, outputformat, obj_id, p_type,
space, buf, depth);
- /* Reclaim any VL memory, if necessary */
- if (vl_data)
- H5Dvlen_reclaim(p_type, space, H5P_DEFAULT, buf);
+ /* Reclaim any VL memory, if necessary */
+ if (vl_data)
+ H5Dvlen_reclaim(p_type, space, H5P_DEFAULT, buf);
+
+ free(buf);
+ } else
+ status = SUCCEED;
- free(buf);
H5Tclose(p_type);
H5Tclose(type);
}
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 5c8631e..bf85bc2 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -2545,6 +2545,9 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info,
}
}
+ if(!sm_nbytes)
+ goto done;
+
assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
sm_buf = (unsigned char *)HDmalloc((size_t)sm_nbytes);
@@ -2619,11 +2622,12 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info,
fputs(OPT(info->line_sep, ""), stream);
}
+ HDfree(sm_buf);
+
+done:
H5Sclose(sm_space);
H5Sclose(f_space);
- HDfree(sm_buf);
-
return SUCCEED;
}