diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2011-08-07 00:16:08 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2011-08-07 00:16:08 (GMT) |
commit | 359ab12d1e7641471f38a8183b049dc6076c37f0 (patch) | |
tree | f72c50ed36ee63fc1e24bd048679f87405992d0d /hl | |
parent | 7d47d81df0989c3e54e652124bb89776ce3926e2 (diff) | |
download | hdf5-359ab12d1e7641471f38a8183b049dc6076c37f0.zip hdf5-359ab12d1e7641471f38a8183b049dc6076c37f0.tar.gz hdf5-359ab12d1e7641471f38a8183b049dc6076c37f0.tar.bz2 |
[svn-r21182] Desciption: brought revision 21157 from the trunk to the branch. Fixes hl bug
HDFFV-7673 -- DS library segfaults when retrieveing length of the dimension label that was not set
Tested: jam (gnu 4.5 compiler)
Diffstat (limited to 'hl')
-rw-r--r-- | hl/src/H5DS.c | 33 | ||||
-rw-r--r-- | hl/test/test_ds.c | 5 |
2 files changed, 25 insertions, 13 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 379b220..4bc4bc4 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -1617,6 +1617,8 @@ out: * Comments: * * Modifications: +* JIRA HDFFV-7673: Added a check to see if the label name exists, +* if not then returns zero. July 30, 2011. MSB * *------------------------------------------------------------------------- */ @@ -1629,7 +1631,7 @@ ssize_t H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size) int rank; /* rank of dataset */ char **buf = NULL; /* buffer to store in the attribute */ H5I_type_t it; /* ID type */ - size_t nbytes; + size_t nbytes = 0; size_t copy_len; int i; @@ -1685,6 +1687,7 @@ ssize_t H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size) if ((aid = H5Aopen(did, DIMENSION_LABELS, H5P_DEFAULT)) < 0) goto out; + if ((tid = H5Aget_type(aid)) < 0) goto out; @@ -1698,26 +1701,30 @@ ssize_t H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size) if (H5Aread(aid, tid, buf) < 0) goto out; - /* get the real string length */ - nbytes = strlen(buf[idx]); + /* do only if the label name exists for the dimension */ + if (buf[idx] != NULL) + { + /* get the real string length */ + nbytes = strlen(buf[idx]); - /* compute the string length which will fit into the user's buffer */ - copy_len = MIN(size-1, nbytes); + /* compute the string length which will fit into the user's buffer */ + copy_len = MIN(size-1, nbytes); - /* copy all/some of the name */ - if (label) - { - memcpy(label, buf[idx], copy_len); + /* copy all/some of the name */ + if (label) + { + memcpy(label, buf[idx], copy_len); + + /* terminate the string */ + label[copy_len] = '\0'; + } - /* terminate the string */ - label[copy_len] = '\0'; } - /* free all the ptr's from the H5Aread() */ for (i = 0; i < rank; i++) { if (buf[i]) - free(buf[i]); + free(buf[i]); } /* close */ diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index 663b18a..1bf268e 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -2918,6 +2918,11 @@ static int test_simple(void) goto out; if(H5DSset_label(did,DIM0,DIM0_LABEL) < 0) goto out; + + /* check getting a label which does not exist */ + if(H5DSget_label(did,DIM1,dim1_label,sizeof(dim1_label)) != 0) + goto out; + if(H5DSset_label(did,DIM1,DIM1_LABEL) < 0) goto out; if(H5DSget_label(did,DIM0,dim0_label,sizeof(dim0_label)) < 0) |