summaryrefslogtreecommitdiff
path: root/library/platform.c
diff options
context:
space:
mode:
authorHanno Becker <hanno.becker@arm.com>2018-10-11 10:26:55 +0100
committerHanno Becker <hanno.becker@arm.com>2018-10-11 11:04:20 +0100
commitcfa2e33fd22d6f78091bac07faedb1e6c4838eeb (patch)
tree11e8c4d41a9cc9862a3ee82a0767131e2dd6386a /library/platform.c
parente5fecec7bf2f0a283e7daff814c726f75caee932 (diff)
Omit runtime configuration of calloc/free if macro config enabled
This commit removes the definition of the API function `mbedtls_platform_set_calloc_free()` from `library/platform.c` in case the macros `MBEDTLS_PLATFORM_CALLOC_MACRO` `MBEDTLS_PLATFORM_FREE_MACRO` for compile time configuration of calloc/free are set. This is in line with the corresponding header `mbedtls/platform.h` which declares `mbedtls_platform_set_calloc_free()` only if `MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO` are not defined. Fixes #1642.
Diffstat (limited to 'library/platform.c')
-rw-r--r--library/platform.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/library/platform.c b/library/platform.c
index b24b2fa6..73a6db9e 100644
--- a/library/platform.c
+++ b/library/platform.c
@@ -30,7 +30,14 @@
#include "mbedtls/platform.h"
#include "mbedtls/platform_util.h"
-#if defined(MBEDTLS_PLATFORM_MEMORY)
+/* The compile time configuration of memory allocation via the macros
+ * MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO takes precedence over the runtime
+ * configuration via mbedtls_platform_set_calloc_free(). So, omit everything
+ * related to the latter if MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO are defined. */
+#if defined(MBEDTLS_PLATFORM_MEMORY) && \
+ !( defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && \
+ defined(MBEDTLS_PLATFORM_FREE_MACRO) )
+
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
static void *platform_calloc_uninit( size_t n, size_t size )
{
@@ -71,7 +78,9 @@ int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
mbedtls_free_func = free_func;
return( 0 );
}
-#endif /* MBEDTLS_PLATFORM_MEMORY */
+#endif /* MBEDTLS_PLATFORM_MEMORY &&
+ !( defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&
+ defined(MBEDTLS_PLATFORM_FREE_MACRO) ) */
#if defined(_WIN32)
#include <stdarg.h>