diff options
Diffstat (limited to 'tests/test_alloc.c')
-rw-r--r-- | tests/test_alloc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_alloc.c b/tests/test_alloc.c index 966814a..95f2b37 100644 --- a/tests/test_alloc.c +++ b/tests/test_alloc.c @@ -10,6 +10,25 @@ #include <stdio.h> #include <string.h> +static void torture_test_calloc(void **state) +{ + void *ptr; + + (void)state; /* unsused */ + + ptr = test_calloc(2, SIZE_MAX); + assert_null(ptr); + ptr = test_calloc(SIZE_MAX, 2); + assert_null(ptr); + + /* overflows to 0 */ + ptr = test_calloc(2, (SIZE_MAX/2)+1); + assert_null(ptr); + + ptr = test_calloc(3, (SIZE_MAX/2)+42); + assert_null(ptr); +} + static void torture_test_malloc(void **state) { char *str; @@ -82,6 +101,7 @@ static void torture_test_realloc_set0(void **state) int main(void) { const struct CMUnitTest alloc_tests[] = { + cmocka_unit_test(torture_test_calloc), cmocka_unit_test(torture_test_malloc), cmocka_unit_test(torture_test_realloc), cmocka_unit_test(torture_test_realloc_set0), |