diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:20:23 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-11-13 15:20:23 (GMT) |
commit | 898ba82d42aa46cbca59fca31f47d5bce3e8dd72 (patch) | |
tree | 33a1c536ed8ed4a1654bf898ccca4622f9547aaf /tools/h5dump | |
parent | dd241064c18efe59768cc5b495fe78b2a779b058 (diff) | |
download | hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.zip hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.tar.gz hdf5-898ba82d42aa46cbca59fca31f47d5bce3e8dd72.tar.bz2 |
[svn-r7844] 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/h5dump')
-rw-r--r-- | tools/h5dump/h5dump.c | 5 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 71 | ||||
-rwxr-xr-x | tools/h5dump/testh5dump.sh | 1 | ||||
-rwxr-xr-x | tools/h5dump/testh5dumpxml.sh | 2 |
4 files changed, 75 insertions, 4 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 5431e21..21913cd 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -4930,7 +4930,8 @@ xml_print_strs(hid_t did, int source) for (i = 0; i < ssiz; i++) { if(is_vlstr) { onestring = *(char **)bp; - str_size = (size_t)strlen(onestring); + if(onestring) + str_size = (size_t)strlen(onestring); } else { strncpy(onestring, bp, tsiz); str_size = tsiz; @@ -4938,7 +4939,7 @@ xml_print_strs(hid_t did, int source) indentation(indent + COL); if (!onestring) { - printf("\"%s\"\n", "NULL"); + printf("NULL\n"); } else { char *t_onestring = xml_escape_the_string(onestring, (int)str_size); diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 690d1c7..002cf89 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -68,6 +68,7 @@ #define FILE40 "tattr2.h5" #define FILE41 "tcompound_complex.h5" #define FILE42 "tnamed_dtype_attr.h5" +#define FILE43 "tvldtypes5.h5" /* prototypes */ @@ -145,6 +146,10 @@ typedef struct s1_t { #define F42_TYPENAME "Datatype" #define F42_ATTRNAME "Attribute" +/* "File 43" macros */ +/* Name of dataset to create in datafile */ +#define F43_DSETNAME "Dataset" + static void gent_group(void) { hid_t fid, group; @@ -2196,6 +2201,67 @@ static void gent_vldatatypes4(void) assert(ret>=0); } +/* Generate a variable-length dataset with NULL values in it */ +static void gent_vldatatypes5(void) +{ + hvl_t wdata [SPACE1_DIM1]; + hid_t fid1; + hid_t dataset; + hid_t sid1; + hid_t tid1; + hsize_t dims1[] = {SPACE1_DIM1}; + int i,j; /* counting variable */ + herr_t ret; /* Generic return value */ + + /* initialize data for dataset */ + for(i=0; i<SPACE1_DIM1; i++) { + if(i%2) { + wdata[i].len=0; + wdata[i].p=NULL; + } /* end if */ + else { + wdata[i].len=i+5; + wdata[i].p=malloc(sizeof(unsigned)*(i+5)); + for(j=0; j<i+5; j++) + ((unsigned *)wdata[i].p)[j]=j*2; + } /* end else */ + } /* end for */ + + /* Create file */ + fid1 = H5Fcreate (FILE43, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + assert(fid1>0); + + /* Create dataspace for datasets */ + sid1 = H5Screate_simple (SPACE1_RANK, dims1, NULL); + assert(sid1>0); + + /* Create a datatype to refer to */ + tid1 = H5Tvlen_create (H5T_NATIVE_UINT); + assert(tid1>0); + + /* Create a dataset */ + dataset = H5Dcreate (fid1, F43_DSETNAME, tid1, sid1, H5P_DEFAULT); + assert(dataset>0); + + ret = H5Dwrite (dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); + assert(ret>=0); + + ret = H5Dclose (dataset); + assert(ret>=0); + + ret = H5Dvlen_reclaim (tid1, sid1, H5P_DEFAULT, wdata); + assert(ret>=0); + + ret = H5Tclose (tid1); + assert(ret>=0); + + ret = H5Sclose (sid1); + assert(ret>=0); + + ret = H5Fclose (fid1); + assert(ret>=0); +} + static void gent_array1(void) { int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */ @@ -2884,8 +2950,8 @@ static void gent_vlstr(void) const char *wdata[SPACE1_DIM1]= { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." + "", + NULL }; /* Information to write */ const char *string_att= "This is the string for the attribute"; hid_t fid1; /* HDF5 File IDs */ @@ -4288,6 +4354,7 @@ int main(void) gent_vldatatypes2(); gent_vldatatypes3(); gent_vldatatypes4(); + gent_vldatatypes5(); gent_array1(); gent_array2(); diff --git a/tools/h5dump/testh5dump.sh b/tools/h5dump/testh5dump.sh index 5a4e902..78e2f03 100755 --- a/tools/h5dump/testh5dump.sh +++ b/tools/h5dump/testh5dump.sh @@ -147,6 +147,7 @@ TOOLTEST tvldtypes1.ddl tvldtypes1.h5 TOOLTEST tvldtypes2.ddl tvldtypes2.h5 TOOLTEST tvldtypes3.ddl tvldtypes3.h5 TOOLTEST tvldtypes4.ddl tvldtypes4.h5 +TOOLTEST tvldtypes5.ddl tvldtypes5.h5 #test for file with variable length string data TOOLTEST tvlstr.ddl tvlstr.h5 diff --git a/tools/h5dump/testh5dumpxml.sh b/tools/h5dump/testh5dumpxml.sh index b7c6f54..d5e3ad5 100755 --- a/tools/h5dump/testh5dumpxml.sh +++ b/tools/h5dump/testh5dumpxml.sh @@ -126,6 +126,8 @@ TOOLTEST tarray7.h5.xml --xml tarray7.h5 TOOLTEST tvldtypes1.h5.xml --xml tvldtypes1.h5 TOOLTEST tvldtypes2.h5.xml --xml tvldtypes2.h5 TOOLTEST tvldtypes3.h5.xml --xml tvldtypes3.h5 +TOOLTEST tvldtypes4.h5.xml --xml tvldtypes4.h5 +TOOLTEST tvldtypes5.h5.xml --xml tvldtypes5.h5 TOOLTEST tvlstr.h5.xml --xml tvlstr.h5 TOOLTEST tsaf.h5.xml --xml tsaf.h5 TOOLTEST tempty.h5.xml --xml tempty.h5 |