From 0eed022034ecf5c8eb07d0d34b26dcea02c68237 Mon Sep 17 00:00:00 2001 From: "Justin R. Cutler" Date: Thu, 7 Apr 2016 08:54:43 -0400 Subject: [PATCH] Check size after allocation_realloc_array test calls. --- test/allocation.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/allocation.c b/test/allocation.c index de07f17..afb8ee9 100644 --- a/test/allocation.c +++ b/test/allocation.c @@ -11,6 +11,8 @@ /* HAVE_* */ #include "config.h" +/* errno, EINVAL */ +#include /* printf, perror */ #include /* EXIT_SUCCESS, EXIT_FAILURE */ @@ -26,6 +28,18 @@ #include +static int test_allocation(allocation_t *allocation, size_t size) +{ + int error = allocation_realloc_array(allocation, 1, size); + if (!error && allocation->size != size) { + /* bad size */ + errno = EINVAL; + error = -1; + } + return error; +} + + static int run(allocator_t *allocator) { int error = 0; @@ -35,16 +49,23 @@ static int run(allocator_t *allocator) allocation_init(&allocation, allocator); for (size = 1; !error && size < (1 << 22); size = size << 1) { - error = allocation_realloc_array(&allocation, 1, size); + error = test_allocation(&allocation, size); + } if (!error) { size_t big = 1UL << (sizeof(size_t) * 4); + size = allocation.size; error = !allocation_realloc_array(&allocation, big, big); + if (!error && allocation.size != size) { + /* bad size */ + errno = EINVAL; + error = -1; + } } for (size = 1 << 22; !error && size; size = size >> 1) { - error = allocation_realloc_array(&allocation, 1, size); + error = test_allocation(&allocation, size); } if (!error) {