aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent41dc8ad77e7e02c5fa0bf91f34f4fd04b6b08dc8 (diff)
Fix reading of string values from HDF5 files
Diffstat (limited to 'src')
-rw-r--r--src/displaywindow.c12
-rw-r--r--src/hdf5-file.c14
2 files changed, 15 insertions, 11 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 0fc71254..1697003f 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -776,13 +776,12 @@ static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh)
static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
const char *group,
- DisplayWindow *dw)
+ DisplayWindow *dw, GSList *rg)
{
char **names;
int *is_group;
int *is_image;
GtkWidget *ms;
- GSList *rg = NULL;
int n, i;
if ( hdfile == NULL ) return NULL;
@@ -803,7 +802,8 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
item = gtk_menu_item_new_with_label(names[i]);
- sub = displaywindow_addhdfgroup(hdfile, names[i], dw);
+ sub = displaywindow_addhdfgroup(hdfile, names[i],
+ dw, rg);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub);
} else if ( is_image[i] ) {
@@ -811,8 +811,10 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
struct newhdf *nh;
item = gtk_radio_menu_item_new_with_label(rg, names[i]);
- rg = gtk_radio_menu_item_get_group(
+ if ( rg == NULL ) {
+ rg = gtk_radio_menu_item_get_group(
GTK_RADIO_MENU_ITEM(item));
+ }
nh = malloc(sizeof(struct newhdf));
if ( nh != NULL ) {
@@ -865,7 +867,7 @@ static void displaywindow_update_menus(DisplayWindow *dw)
GtkWidget *ms;
GtkWidget *w;
- ms = displaywindow_addhdfgroup(dw->hdfile, "/", dw);
+ ms = displaywindow_addhdfgroup(dw->hdfile, "/", dw, NULL);
if ( ms == NULL ) {
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);