aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-04-16 11:33:24 +0200
committerThomas White <taw@physics.org>2010-04-16 11:33:24 +0200
commita2b1629e8de565d423eb0f91428853362adf5df6 (patch)
tree10c86cc7a232ec3d1b1b596f4a3d5acfd8e84e27 /src/hdf5-file.c
parent41dc8ad77e7e02c5fa0bf91f34f4fd04b6b08dc8 (diff)
Fix reading of string values from HDF5 files
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index cb24fa48..85c68b85 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -273,18 +273,20 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name)
herr_t r;
char *tmp;
- hid_t th;
-
- size = H5Dget_storage_size(dh);
+ hid_t sh;
+ size = H5Tget_size(type);
tmp = malloc(size+1);
- th = H5Tcopy(H5T_C_S1);
- H5Tset_size(th, size+1);
+ sh = H5Screate(H5S_SCALAR);
- r = H5Dread(dh, th, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp);
+ r = H5Dread(dh, type, sh, sh, H5P_DEFAULT, tmp);
if ( r < 0 ) goto fail;
+ /* Two possibilities:
+ * String is already zero-terminated
+ * String is not terminated.
+ * Make sure things are done properly... */
tmp[size] = '\0';
chomp(tmp);