From c0f96bb27636de407a29c8ee30bb44a03c74a0fb Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 1 Jun 2013 00:35:39 -0400 Subject: [PATCH] mem-overflow: test malloc and realloc corner cases --- glib/tests/mem-overflow.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/glib/tests/mem-overflow.c b/glib/tests/mem-overflow.c index 44ae333ae..d072e5d73 100644 --- a/glib/tests/mem-overflow.c +++ b/glib/tests/mem-overflow.c @@ -64,6 +64,26 @@ MEM_OVERFLOW_TEST (new0_b, p = g_new0 (X, b)) MEM_OVERFLOW_TEST (renew_a, p = g_malloc (1); p = g_renew (X, p, a)) MEM_OVERFLOW_TEST (renew_b, p = g_malloc (1); p = g_renew (X, p, b)) +static void +mem_overflow_malloc_0 (void) +{ + gpointer p; + + p = g_malloc (0); + g_assert (p == NULL); +} + +static void +mem_overflow_realloc_0 (void) +{ + gpointer p; + + p = g_malloc (10); + g_assert (p != NULL); + p = g_realloc (p, 0); + g_assert (p == NULL); +} + static void mem_overflow (void) { @@ -144,6 +164,9 @@ mem_overflow (void) CHECK_SUBPROCESS_FAIL (renew_a); CHECK_SUBPROCESS_PASS (renew_b); + + CHECK_SUBPROCESS_PASS (malloc_0); + CHECK_SUBPROCESS_PASS (realloc_0); } typedef struct @@ -198,6 +221,8 @@ main (int argc, g_test_add_func ("/mem/overflow/subprocess/new0_b", mem_overflow_new0_b); g_test_add_func ("/mem/overflow/subprocess/renew_a", mem_overflow_renew_a); g_test_add_func ("/mem/overflow/subprocess/renew_b", mem_overflow_renew_b); + g_test_add_func ("/mem/overflow/subprocess/malloc_0", mem_overflow_malloc_0); + g_test_add_func ("/mem/overflow/subprocess/realloc_0", mem_overflow_realloc_0); g_test_add_func ("/mem/empty-alloc", empty_alloc); g_test_add_func ("/mem/empty-alloc/subprocess", empty_alloc_subprocess);