summaryrefslogtreecommitdiffstats
path: root/test/tvlstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tvlstr.c')
-rw-r--r--test/tvlstr.c82
1 files changed, 59 insertions, 23 deletions
diff --git a/test/tvlstr.c b/test/tvlstr.c
index a411b86..fbced5f 100644
--- a/test/tvlstr.c
+++ b/test/tvlstr.c
@@ -573,7 +573,7 @@ static void test_write_vl_string_attribute(void)
hid_t file, root, dataspace, att;
hid_t type;
herr_t ret;
- char *string_att_check;
+ char *string_att_check = NULL;
/* Open the file */
file = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT);
@@ -599,13 +599,21 @@ static void test_write_vl_string_attribute(void)
ret = H5Awrite(att, type, &string_att);
CHECK(ret, FAIL, "H5Awrite");
- ret = H5Aread(att, type, &string_att_check);
- CHECK(ret, FAIL, "H5Aread");
+ /* Allocate memory for read buffer */
+ if(string_att)
+ string_att_check = (char*)HDmalloc((strlen(string_att) + 1) * sizeof(char));
+ CHECK(string_att_check, NULL, "HDmalloc");
- if(HDstrcmp(string_att_check,string_att)!=0)
- TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check);
+ if(string_att_check) {
+ ret = H5Aread(att, type, &string_att_check);
+ CHECK(ret, FAIL, "H5Aread");
- HDfree(string_att_check);
+ if(HDstrcmp(string_att_check,string_att)!=0)
+ TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check);
+
+ HDfree(string_att_check);
+ string_att_check = NULL;
+ }
ret = H5Aclose(att);
CHECK(ret, FAIL, "HAclose");
@@ -620,13 +628,23 @@ static void test_write_vl_string_attribute(void)
ret = H5Awrite(att, type, &string_att_write);
CHECK(ret, FAIL, "H5Awrite");
- ret = H5Aread(att, type, &string_att_check);
- CHECK(ret, FAIL, "H5Aread");
+ /* Allocate memory for read buffer */
+ if(string_att_write)
+ string_att_check = (char*)HDmalloc((strlen(string_att_write) + 1) * sizeof(char));
+ CHECK(string_att_check, NULL, "HDmalloc");
+
+ if(string_att_check) {
+ ret = H5Aread(att, type, &string_att_check);
+ CHECK(ret, FAIL, "H5Aread");
- if(HDstrcmp(string_att_check,string_att_write)!=0)
- TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check);
+ if(HDstrcmp(string_att_check,string_att_write)!=0)
+ TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check);
+
+ /* The attribute string written is freed below, in the
+ *test_read_vl_string_attribute() test */
+ HDfree(string_att_check);
+ }
- HDfree(string_att_check);
/* The attribute string written is freed below, in the test_read_vl_string_attribute() test */
/* HDfree(string_att_write); */
@@ -659,7 +677,7 @@ static void test_read_vl_string_attribute(void)
hid_t file, root, att;
hid_t type;
herr_t ret;
- char *string_att_check;
+ char *string_att_check = NULL;
/* Open file */
file = H5Fopen(DATAFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
@@ -679,13 +697,21 @@ static void test_read_vl_string_attribute(void)
att = H5Aopen(root, "test_scalar", H5P_DEFAULT);
CHECK(att, FAIL, "H5Aopen");
- ret = H5Aread(att, type, &string_att_check);
- CHECK(ret, FAIL, "H5Aread");
+ /* Allocate memory for read buffer */
+ if(string_att)
+ string_att_check = (char*)HDmalloc((strlen(string_att) + 1) * sizeof(char));
+ CHECK(string_att_check, NULL, "HDmalloc");
- if(HDstrcmp(string_att_check,string_att)!=0)
- TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check);
+ if(string_att_check) {
+ ret = H5Aread(att, type, &string_att_check);
+ CHECK(ret, FAIL, "H5Aread");
- HDfree(string_att_check);
+ if(HDstrcmp(string_att_check,string_att)!=0)
+ TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check);
+
+ HDfree(string_att_check);
+ string_att_check = NULL;
+ }
ret = H5Aclose(att);
CHECK(ret, FAIL, "HAclose");
@@ -694,14 +720,24 @@ static void test_read_vl_string_attribute(void)
att = H5Aopen(root, "test_scalar_large", H5P_DEFAULT);
CHECK(att, FAIL, "H5Aopen");
- ret = H5Aread(att, type, &string_att_check);
- CHECK(ret, FAIL, "H5Aread");
+ /* Allocate memory for read buffer */
+ if(string_att_write)
+ string_att_check = (char*)HDmalloc((strlen(string_att_write) + 1) * sizeof(char));
+ CHECK(string_att_check, NULL, "HDmalloc");
+
+ if(string_att_check) {
+ ret = H5Aread(att, type, &string_att_check);
+ CHECK(ret, FAIL, "H5Aread");
- if(HDstrcmp(string_att_check,string_att_write)!=0)
- TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check);
+ if(HDstrcmp(string_att_check,string_att_write)!=0)
+ TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check);
+
+ HDfree(string_att_check);
+ }
- HDfree(string_att_check);
- HDfree(string_att_write); /* Free string allocated in test_write_vl_string_attribute */
+ /* Free string allocated in test_write_vl_string_attribute */
+ if(string_att_write)
+ HDfree(string_att_write);
ret = H5Aclose(att);
CHECK(ret, FAIL, "HAclose");