summaryrefslogtreecommitdiffstats
path: root/test/tattr.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2009-06-26 19:41:32 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2009-06-26 19:41:32 (GMT)
commitd8c0ebd42824f24ab457c1b98c90d0531f899103 (patch)
treee11a6f171dc2f4a893c5067d093434ee46ef3aef /test/tattr.c
parent084ab0cbde453e8f5847abbb06bc94cfe6f3e657 (diff)
downloadhdf5-d8c0ebd42824f24ab457c1b98c90d0531f899103.zip
hdf5-d8c0ebd42824f24ab457c1b98c90d0531f899103.tar.gz
hdf5-d8c0ebd42824f24ab457c1b98c90d0531f899103.tar.bz2
[svn-r17119] Bug fix #1513. Reading an empty attribute caused seg fault. The flag "initialized" in
the attribute structure wan't set correctly. It caused some confusion in H5A_read. This flag was actually redundant because the library can alwasy check if the data buffer is present. To fix it, I removed the "initialized" flag in the attribute structure and let H5A_read check the data buffer. Tested on jam, smirom, and linex.
Diffstat (limited to 'test/tattr.c')
-rw-r--r--test/tattr.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/tattr.c b/test/tattr.c
index 4b130e6..5eb378f 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -10145,6 +10145,66 @@ test_attr_bug5(hid_t fcpl, hid_t fapl)
/****************************************************************
**
+** test_attr_bug6(): Test basic H5A (attribute) code.
+** Tests if reading an empty attribute is OK.
+**
+****************************************************************/
+static void
+test_attr_bug6(hid_t fcpl, hid_t fapl)
+{
+ hid_t fid; /* File ID */
+ hid_t gid; /* Group ID */
+ hid_t aid1, aid2; /* Attribute IDs */
+ hid_t sid; /* Dataspace ID */
+ hsize_t dims[1] = {5}; /* Attribute dimensions */
+ int intar[5]; /* Data reading buffer */
+ herr_t ret; /* Generic return status */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing that empty attribute can be read\n"));
+
+ /* Create file */
+ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ /* Open root group */
+ gid = H5Gopen2(fid, "/", H5P_DEFAULT);
+ CHECK(gid, FAIL, "H5Gcreate2");
+
+ /* Create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+ CHECK(sid, FAIL, "H5Screate_simple");
+
+ /* Create attribute on group */
+ aid1 = H5Acreate2(gid, "attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(aid1, FAIL, "H5Acreate2");
+
+ ret = H5Aclose(aid1);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Open the attribute again */
+ aid2 = H5Aopen_name(gid, "attr");
+ CHECK(aid2, FAIL, "H5Aopen_name");
+
+ ret = H5Aread(aid2, H5T_NATIVE_INT, intar);
+ CHECK(ret, FAIL, "H5Aread");
+
+ /* Close IDs */
+ ret = H5Aclose(aid2);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ ret = H5Gclose(gid);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+}
+
+/****************************************************************
+**
** test_attr(): Main H5A (attribute) testing routine.
**
****************************************************************/
@@ -10288,6 +10348,7 @@ test_attr(void)
test_attr_bug3(my_fcpl, my_fapl); /* Test "self referential" attributes */
test_attr_bug4(my_fcpl, my_fapl); /* Test attributes on named datatypes */
test_attr_bug5(my_fcpl, my_fapl); /* Test opening/closing attributes through different file handles */
+ test_attr_bug6(my_fcpl, my_fapl); /* Test reading empty attribute */
} /* end for */
} /* end if */
else {
@@ -10311,6 +10372,7 @@ test_attr(void)
test_attr_bug3(fcpl, my_fapl); /* Test "self referential" attributes */
test_attr_bug4(fcpl, my_fapl); /* Test attributes on named datatypes */
test_attr_bug5(fcpl, my_fapl); /* Test opening/closing attributes through different file handles */
+ test_attr_bug6(fcpl, my_fapl); /* Test reading empty attribute */
} /* end else */
} /* end for */