summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-04-25 16:38:56 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-04-25 16:38:56 (GMT)
commit0efc913a6799080c5399a761f603cd80b93e71f0 (patch)
tree81dcd8d246fb4207a9c49e1904ce91259ec4c919
parentfbd98fe9fb6566e00b2401466b3584f325494cfc (diff)
downloadhdf5-0efc913a6799080c5399a761f603cd80b93e71f0.zip
hdf5-0efc913a6799080c5399a761f603cd80b93e71f0.tar.gz
hdf5-0efc913a6799080c5399a761f603cd80b93e71f0.tar.bz2
[svn-r20624] 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, linew, and amani.
-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 1b140ac..6ac32f3 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2495,7 +2495,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;
@@ -2645,45 +2645,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 3cce2e5..3d29d39 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -2550,6 +2550,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);
@@ -2624,11 +2627,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;
}