summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2017-11-11 05:15:50 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2017-11-11 05:15:50 (GMT)
commitd4a0e3d293596dcd0412c7cc02f18addf44d03d5 (patch)
tree5c080f4f76f4dec7287b1c67a968c957bbfb737a /test
parent6663efbf6618f14eb66324e18a7a8e2632f96cf2 (diff)
parent3e4f6138b60d8363c377e453d63f875775ec907a (diff)
downloadhdf5-d4a0e3d293596dcd0412c7cc02f18addf44d03d5.zip
hdf5-d4a0e3d293596dcd0412c7cc02f18addf44d03d5.tar.gz
hdf5-d4a0e3d293596dcd0412c7cc02f18addf44d03d5.tar.bz2
Merge pull request #767 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:zero_allocation_fix_develop to develop
* commit '3e4f6138b60d8363c377e453d63f875775ec907a': Removed asserts from H5MM calls that conflict with stated behavior and added a test to ensure that this doesn't happen in the future.
Diffstat (limited to 'test')
-rw-r--r--test/tmisc.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/test/tmisc.c b/test/tmisc.c
index 102325a..6da4589 100644
--- a/test/tmisc.c
+++ b/test/tmisc.c
@@ -30,6 +30,7 @@
#include "testhdf5.h"
#include "H5srcdir.h"
#include "H5Dpkg.h" /* Datasets */
+#include "H5MMprivate.h" /* Memory */
/* Definitions for misc. test #1 */
#define MISC1_FILE "tmisc1.h5"
@@ -5526,6 +5527,64 @@ test_misc33(void)
} /* end test_misc33() */
+/****************************************************************
+**
+** test_misc34(): Ensure zero-size memory allocations work
+**
+****************************************************************/
+static void
+test_misc34(void)
+{
+ void *mem = NULL; /* allocated buffer */
+ char *dup = NULL; /* 'duplicated' string */
+ size_t sz = 0; /* buffer size */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing O and NULL behavior in H5MM API calls"));
+
+ /* H5MM_xfree(): Ensure that passing NULL is allowed and returns NULL */
+ mem = H5MM_xfree(mem);
+ CHECK_PTR_NULL(mem, "H5MM_xfree");
+
+ /* H5MM_malloc(): Ensure that size 0 returns NULL */
+ mem = H5MM_malloc(sz);
+ CHECK_PTR_NULL(mem, "H5MM_malloc");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_calloc(): Ensure that size 0 returns NULL */
+ mem = H5MM_calloc(sz);
+ CHECK_PTR_NULL(mem, "H5MM_calloc");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_realloc(): Check behavior:
+ *
+ * H5MM_realloc(NULL, size) <==> H5MM_malloc(size)
+ * H5MM_realloc(ptr, 0) <==> H5MM_xfree(ptr)
+ * H5MM_realloc(NULL, 0) <==> NULL
+ */
+ mem = H5MM_xfree(mem);
+
+ sz = 1024;
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR(mem, "H5MM_realloc (case 1)");
+ /* Don't free mem here! */
+
+ sz = 0;
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR_NULL(mem, "H5MM_realloc (case 2)");
+ mem = H5MM_xfree(mem);
+
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR_NULL(mem, "H5MM_realloc (case 3)");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_xstrdup(): Ensure NULL returns NULL */
+ dup = H5MM_xstrdup((const char *)mem);
+ CHECK_PTR_NULL(dup, "H5MM_xstrdup");
+ dup = (char *)H5MM_xfree((void *)dup);
+
+} /* end test_misc34() */
+
/****************************************************************
**
@@ -5575,6 +5634,7 @@ test_misc(void)
test_misc31(); /* Test Reentering library through deprecated routines after H5close() */
test_misc32(); /* Test filter memory allocation functions */
test_misc33(); /* Test to verify that H5HL_offset_into() returns error if offset exceeds heap block */
+ test_misc34(); /* Test behavior of 0 and NULL in H5MM API calls */
} /* test_misc() */
@@ -5632,5 +5692,5 @@ cleanup_misc(void)
HDremove(MISC29_COPY_FILE);
HDremove(MISC30_FILE);
HDremove(MISC31_FILE);
-}
+} /* end cleanup_misc() */