diff --git a/harness.c b/harness.c index 64250ae12..544d5a28d 100644 --- a/harness.c +++ b/harness.c @@ -161,6 +161,18 @@ void *test_malloc(size_t size) return p; } +// cppcheck-suppress unusedFunction +void *test_calloc(size_t nelem, size_t elsize) +{ + /* Reference: Malloc tutorial + * https://danluu.com/malloc-tutorial/ + */ + size_t size = nelem * elsize; // TODO: check for overflow + void *ptr = test_malloc(size); + memset(ptr, 0, size); + return ptr; +} + void test_free(void *p) { if (noallocate_mode) { diff --git a/harness.h b/harness.h index 73cafc570..3956b7003 100644 --- a/harness.h +++ b/harness.h @@ -12,6 +12,7 @@ */ void *test_malloc(size_t size); +void *test_calloc(size_t nmemb, size_t size); void test_free(void *p); char *test_strdup(const char *s); /* FIXME: provide test_realloc as well */