From 5f049dc50c9c66d2fafbcb5ccb34dbcf85668150 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 28 Nov 2000 15:11:06 -0500 Subject: [svn-r3014] Purpose: Bug fix. Description: Data dumping routines weren't correctly handling scalar dataspaces when dumping them. Under some circumstances, it would get into infinite loops. Solution: Small patches to avoid problems when the number of dimensions is zero. Platforms tested: FreeBSD 4.2 (hawkwind) --- tools/h5tools.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/h5tools.c b/tools/h5tools.c index a7754fe..41532b6 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -1497,13 +1497,17 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, return -1; /* Assume entire data space to be printed */ - for (i = 0; i < (hsize_t)ctx.ndims; i++) - ctx.p_min_idx[i] = 0; + if(ctx.ndims>0) + for (i = 0; i < (hsize_t)ctx.ndims; i++) + ctx.p_min_idx[i] = 0; H5Sget_simple_extent_dims(f_space, total_size, NULL); - for (i = 0, p_nelmts = 1; i < (hsize_t)ctx.ndims; i++) - p_nelmts *= total_size[i]; + if(ctx.ndims>0) + for (i = 0, p_nelmts = 1; i < (hsize_t)ctx.ndims; i++) + p_nelmts *= total_size[i]; + else + p_nelmts = 1; if (p_nelmts == 0) return 0; /*nothing to print*/ @@ -1516,11 +1520,14 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, */ p_type_nbytes = H5Tget_size(p_type); - for (i = ctx.ndims, sm_nbytes = p_type_nbytes; i > 0; --i) { - sm_size[i - 1] = MIN(total_size[i - 1], H5DUMP_BUFSIZE / sm_nbytes); - sm_nbytes *= sm_size[i - 1]; - assert(sm_nbytes > 0); - } + if(ctx.ndims>0) + for (i = ctx.ndims, sm_nbytes = p_type_nbytes; i > 0; --i) { + sm_size[i - 1] = MIN(total_size[i - 1], H5DUMP_BUFSIZE / sm_nbytes); + sm_nbytes *= sm_size[i - 1]; + assert(sm_nbytes > 0); + } + else + sm_nbytes = p_type_nbytes; sm_buf = malloc(sm_nbytes); sm_nelmts = sm_nbytes / p_type_nbytes; -- cgit v0.12