From 2b112ea5932d280288882d8bb38e7942b166fe5a Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Tue, 9 Oct 2018 08:41:36 -0700 Subject: [PATCH] add test for zero-sized alloc and aligned alloc --- Makefile.in | 1 + test/integration/aligned_alloc.c | 12 +++++++++++- test/integration/malloc.c | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/integration/malloc.c diff --git a/Makefile.in b/Makefile.in index 3d99a409..c9bd95a3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -226,6 +226,7 @@ endif TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \ $(srcroot)test/integration/allocated.c \ $(srcroot)test/integration/extent.c \ + $(srcroot)test/integration/malloc.c \ $(srcroot)test/integration/mallocx.c \ $(srcroot)test/integration/MALLOCX_ARENA.c \ $(srcroot)test/integration/overflow.c \ diff --git a/test/integration/aligned_alloc.c b/test/integration/aligned_alloc.c index cfe1df9d..4375b172 100644 --- a/test/integration/aligned_alloc.c +++ b/test/integration/aligned_alloc.c @@ -138,10 +138,20 @@ TEST_BEGIN(test_alignment_and_size) { } TEST_END +TEST_BEGIN(test_zero_alloc) { + void *res = aligned_alloc(8, 0); + assert(res); + size_t usable = malloc_usable_size(res); + assert(usable > 0); + free(res); +} +TEST_END + int main(void) { return test( test_alignment_errors, test_oom_errors, - test_alignment_and_size); + test_alignment_and_size, + test_zero_alloc); } diff --git a/test/integration/malloc.c b/test/integration/malloc.c new file mode 100644 index 00000000..8b33bc8f --- /dev/null +++ b/test/integration/malloc.c @@ -0,0 +1,16 @@ +#include "test/jemalloc_test.h" + +TEST_BEGIN(test_zero_alloc) { + void *res = malloc(0); + assert(res); + size_t usable = malloc_usable_size(res); + assert(usable > 0); + free(res); +} +TEST_END + +int +main(void) { + return test( + test_zero_alloc); +}