From 4b627af36c67f1cecf740035b17abbf0d01f9990 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 7 Jul 2021 21:02:36 +0200 Subject: [PATCH] New macro MBEDTLS_CHECK_RETURN Put this macro before a function declaration to indicate that its result must be checked. This commit supports GCC-like compilers and MSVC >=2012. Signed-off-by: Gilles Peskine --- include/mbedtls/build_info.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/mbedtls/build_info.h b/include/mbedtls/build_info.h index 23f85ba01e..46717608be 100644 --- a/include/mbedtls/build_info.h +++ b/include/mbedtls/build_info.h @@ -53,6 +53,24 @@ #define _CRT_SECURE_NO_DEPRECATE 1 #endif +/** \def MBEDTLS_CHECK_RETURN + * + * This macro appearing at the beginning of the declaration of a function + * indicates that its return value should be checked. + * + * This should appear before most functions returning an error code + * (as \c int in the \c mbedtls_xxx API or + * as ::psa_status_t in the \c psa_xxx API). + */ +#if defined(__GNUC__) +#define MBEDTLS_CHECK_RETURN __attribute__((warn_unused_result)) +#elif defined(_MSC_VER) && _MSC_VER >= 1700 +#include +#define MBEDTLS_CHECK_RETURN _Check_return_ +#else +#define MBEDTLS_CHECK_RETURN +#endif + #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/mbedtls_config.h" #else