blob: c1a1214fded1bb2fe0aa37dfa69bf92531005b18 [file] [log] [blame]
Ronald Cron42ba65d2024-12-05 10:54:33 +01001/* crypto_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 Rodgman16799db2023-11-02 19:47:20 +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 Axtens09e34b72021-09-30 17:19:34 +100010
11#ifndef MBEDTLS_PLATFORM_STD_CALLOC
Gilles Peskine449bd832023-01-11 14:50:10 +010012static inline void *custom_calloc(size_t nmemb, size_t size)
Gilles Peskinec4ef7a92019-09-17 19:04:38 +020013{
Gilles Peskine449bd832023-01-11 14:50:10 +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 Axtens09e34b72021-09-30 17:19:34 +100022#endif