blob: d74a8516ea045f66abc15cc19481162258a7ddaf [file] [log] [blame]
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02001/* config.h modifier that forces calloc(0) to return NULL.
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002 * Used for testing.
3 */
4/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02005 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00006 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02007 */
8
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02009#include <stdlib.h>
Daniel Axtensb3f25b02022-02-22 07:50:47 -050010
11#ifndef MBEDTLS_PLATFORM_STD_CALLOC
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010012static inline void *custom_calloc(size_t nmemb, size_t size)
Gilles Peskinec4ef7a92019-09-17 19:04:38 +020013{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010014 if (nmemb == 0 || size == 0) {
15 return NULL;
16 }
17 return calloc(nmemb, size);
Gilles Peskinec4ef7a92019-09-17 19:04:38 +020018}
19
20#define MBEDTLS_PLATFORM_MEMORY
21#define MBEDTLS_PLATFORM_STD_CALLOC custom_calloc
Daniel Axtensb3f25b02022-02-22 07:50:47 -050022#endif