Make MBEDTLS_IGNORE_RETURN configurable

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-09-30 18:56:17 +02:00
parent 327cb72e76
commit c2779328bf
2 changed files with 16 additions and 2 deletions

View file

@ -3733,6 +3733,14 @@
*/ */
//#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__)) //#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
/** \def MBEDTLS_IGNORE_RETURN
*
* This macro requires one argument, which should be a C function call.
* If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this
* warning is suppressed.
*/
//#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result))
/* PSA options */ /* PSA options */
/** /**
* Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the * Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the

View file

@ -176,6 +176,9 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
* #MBEDTLS_CHECK_RETURN is implemented for the compiler in use and * #MBEDTLS_CHECK_RETURN is implemented for the compiler in use and
* #MBEDTLS_CHECK_RETURN_WARNING is enabled in the compile-time configuration. * #MBEDTLS_CHECK_RETURN_WARNING is enabled in the compile-time configuration.
* *
* You can use #MBEDTLS_IGNORE_RETURN to explicitly ignore the return value
* of a function that is annotated with #MBEDTLS_CHECK_RETURN.
*
* \note The use of this macro is a work in progress. * \note The use of this macro is a work in progress.
* This macro will be added to more functions in the future. * This macro will be added to more functions in the future.
* Eventually this should appear before most functions returning * Eventually this should appear before most functions returning
@ -203,8 +206,10 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
/** \def MBEDTLS_IGNORE_RETURN /** \def MBEDTLS_IGNORE_RETURN
* *
* Silences warning about unused return value given by functions * Call this macro with one argument, a function call, to suppress a warning
* with \c MBEDTLS_CHECK_RETURN attribute. * from #MBEDTLS_CHECK_RETURN due to that function call.
*/
#if !defined(MBEDTLS_IGNORE_RETURN)
/* GCC doesn't silence the warning with just (void)(result). /* GCC doesn't silence the warning with just (void)(result).
* !(void)(result) is known to work up at least up to GCC 10, as well * !(void)(result) is known to work up at least up to GCC 10, as well
* as with Clang and MSVC. * as with Clang and MSVC.
@ -214,6 +219,7 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
*/ */
#define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) ) #define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) )
#endif
/** /**
* \brief Securely zeroize a buffer * \brief Securely zeroize a buffer