From ef01852d65987a461621b06306d80cb42be6ed0e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 12 Apr 2021 17:27:18 +0100 Subject: [PATCH] Add missing guard to mbedtls_test_hook_error_add Add a missing guard for the definition and declaration of mbedtls_test_hook_error_add. Also make the declaration always visible when MBEDTLS_TEST_HOOKS is enabled. This fixes an issue when MBEDTLS_ERROR_C is not defined but MBEDTLS_TEST_HOOKS is. Signed-off-by: Chris Jones --- include/mbedtls/error.h | 2 ++ library/error.c | 6 ++++-- scripts/data_files/error.fmt | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 624228914..49c312082 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -123,11 +123,13 @@ extern "C" { #define MBEDTLS_ERROR_ADD( high, low ) \ mbedtls_error_add_ext( high, low, __FILE__, __LINE__ ) +#if defined(MBEDTLS_TEST_HOOKS) /** * \brief Testing hook called before adding/combining two error codes together. * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +#endif /** * \brief Combines a high-level and low-level error code together. diff --git a/library/error.c b/library/error.c index b5bd8d77c..afad38904 100644 --- a/library/error.c +++ b/library/error.c @@ -893,8 +893,6 @@ const char * mbedtls_low_level_strerr( int error_code ) return( NULL ); } -void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); - void mbedtls_strerror( int ret, char *buf, size_t buflen ) { size_t len; @@ -975,4 +973,8 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #endif /* MBEDTLS_ERROR_C */ +#if defined(MBEDTLS_TEST_HOOKS) +void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +#endif + #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 7fed598ea..3be94bd2c 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -82,8 +82,6 @@ LOW_LEVEL_CODE_CHECKS return( NULL ); } -void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); - void mbedtls_strerror( int ret, char *buf, size_t buflen ) { size_t len; @@ -164,4 +162,8 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #endif /* MBEDTLS_ERROR_C */ +#if defined(MBEDTLS_TEST_HOOKS) +void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +#endif + #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */