summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-11-13 15:19:50 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-11-13 15:19:50 (GMT)
commite1792ebb22c1fee3eb349b83543e6e915bd1e6f7 (patch)
tree6e3f936d7809ff0191d17454ba0cb6047abda784 /tools/lib
parent71f3513337e800f6500551448559cecc6853aca9 (diff)
downloadhdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.zip
hdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.tar.gz
hdf5-e1792ebb22c1fee3eb349b83543e6e915bd1e6f7.tar.bz2
[svn-r7842] Purpose:
Bug fix Description: Variable length strings and sequences with NULL pointers were not handled by library, causing problems access the data. This also affected fill values for variable-length datatypes. Solution: Address the issues in the library by detecting NULL sequences/strings and avoid trying to convert them. Patched up dumper to display NULL sequences/strings. Platforms tested: FreeBSD 4.9 (sleipnir) h5committest
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5tools_str.c102
1 files changed, 55 insertions, 47 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
index de1bf72..b3ee8e3 100644
--- a/tools/lib/h5tools_str.c
+++ b/tools/lib/h5tools_str.c
@@ -510,8 +510,8 @@ char *
h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
hid_t type, void *vp, h5tools_context_t *ctx)
{
- size_t n, offset, size, nelmts, start;
- char *name, quote = '\0';
+ size_t n, offset, size=0, nelmts, start;
+ char *name;
unsigned char *ucp_vp = (unsigned char *)vp;
char *cp_vp = (char *)vp;
hid_t memb, obj, region;
@@ -567,6 +567,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
h5tools_print_char(str, info, (unsigned char)(*ucp_vp));
} else if (H5T_STRING == H5Tget_class(type)) {
unsigned int i;
+ char quote = '\0';
char *s;
quote = '\0';
@@ -574,64 +575,71 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
/* cp_vp is the pointer into the struct where a `char*' is stored. So we have
* to dereference the pointer to get the `char*' to pass to HDstrlen(). */
s = *(char**)cp_vp;
- size = HDstrlen(s);
+ if(s!=NULL)
+ size = HDstrlen(s);
} else {
s = cp_vp;
size = H5Tget_size(type);
}
pad = H5Tget_strpad(type);
- for (i=0; i<size && (s[i] || pad!=H5T_STR_NULLTERM); i++) {
- int j = 1;
-
- /*
- * Count how many times the next character repeats. If the
- * threshold is zero then that means it can repeat any number
- * of times.
- */
- if (info->str_repeat > 0)
- while (i + j < size && s[i] == s[i + j])
- j++;
-
- /*
- * Print the opening quote. If the repeat count is high enough to
- * warrant printing the number of repeats instead of enumerating
- * the characters, then make sure the character to be repeated is
- * in it's own quote.
- */
- if (info->str_repeat > 0 && j > info->str_repeat) {
- if (quote)
- h5tools_str_append(str, "%c", quote);
-
- quote = '\'';
- h5tools_str_append(str, "%s%c", i ? " " : "", quote);
- } else if (!quote) {
- quote = '"';
- h5tools_str_append(str, "%s%c", i ? " " : "", quote);
- }
+ /* Check for NULL pointer for string */
+ if(s==NULL) {
+ h5tools_str_append(str, "NULL");
+ }
+ else {
+ for (i=0; i<size && (s[i] || pad!=H5T_STR_NULLTERM); i++) {
+ int j = 1;
+
+ /*
+ * Count how many times the next character repeats. If the
+ * threshold is zero then that means it can repeat any number
+ * of times.
+ */
+ if (info->str_repeat > 0)
+ while (i + j < size && s[i] == s[i + j])
+ j++;
- /* Print the character */
- h5tools_print_char(str, info, (unsigned char)(s[i]));
-
- /* Print the repeat count */
- if (info->str_repeat && j > info->str_repeat) {
+ /*
+ * Print the opening quote. If the repeat count is high enough to
+ * warrant printing the number of repeats instead of enumerating
+ * the characters, then make sure the character to be repeated is
+ * in it's own quote.
+ */
+ if (info->str_repeat > 0 && j > info->str_repeat) {
+ if (quote)
+ h5tools_str_append(str, "%c", quote);
+
+ quote = '\'';
+ h5tools_str_append(str, "%s%c", i ? " " : "", quote);
+ } else if (!quote) {
+ quote = '"';
+ h5tools_str_append(str, "%s%c", i ? " " : "", quote);
+ }
+
+ /* Print the character */
+ h5tools_print_char(str, info, (unsigned char)(s[i]));
+
+ /* Print the repeat count */
+ if (info->str_repeat && j > info->str_repeat) {
#ifdef REPEAT_VERBOSE
- h5tools_str_append(str, "%c repeats %d times", quote, j - 1);
+ h5tools_str_append(str, "%c repeats %d times", quote, j - 1);
#else
- h5tools_str_append(str, "%c*%d", quote, j - 1);
+ h5tools_str_append(str, "%c*%d", quote, j - 1);
#endif /* REPEAT_VERBOSE */
- quote = '\0';
- i += j - 1;
- }
+ quote = '\0';
+ i += j - 1;
+ }
- }
+ }
- if (quote)
- h5tools_str_append(str, "%c", quote);
+ if (quote)
+ h5tools_str_append(str, "%c", quote);
- if (i == 0)
- /*empty string*/
- h5tools_str_append(str, "\"\"");
+ if (i == 0)
+ /*empty string*/
+ h5tools_str_append(str, "\"\"");
+ } /* end else */
} else if (H5Tequal(type, H5T_NATIVE_INT)) {
memcpy(&tempint, vp, sizeof(int));
h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint);