From 327cb72e76dd8803f4d98edd4e75b87400bee3b1 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 30 Sep 2021 18:54:51 +0200 Subject: [PATCH] Cleaner implementation of MBEDTLS_IGNORE_RETURN The previous implementation was misparsed in constructs like `if (condition) MBEDTLS_IGNORE_RETURN(...); else ...;`. Implement it as an expression, tested with GCC, Clang and MSVC. Signed-off-by: Gilles Peskine --- include/mbedtls/platform_util.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h index a90c10a4aa..7e8046a47d 100644 --- a/include/mbedtls/platform_util.h +++ b/include/mbedtls/platform_util.h @@ -205,8 +205,15 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; * * Silences warning about unused return value given by functions * with \c MBEDTLS_CHECK_RETURN attribute. +/* 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 + * as with Clang and MSVC. + * + * https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Non_002dbugs.html + * https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34 */ -#define MBEDTLS_IGNORE_RETURN(result) if( result ) {} +#define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) ) /** * \brief Securely zeroize a buffer