From 9c29d87beebf3a4d60639977494add18c45acba6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 19 Dec 2022 21:07:39 +0900 Subject: [PATCH] macro: check existence of cleanup function before call it The free function specified in the macro may be provided by a dynamically loaded library. Replaces #25781. --- src/basic/macro.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 3d1b175123..a00d60824d 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -64,10 +64,14 @@ _Pragma("GCC diagnostic push") #endif -#define DISABLE_WARNING_TYPE_LIMITS \ +#define DISABLE_WARNING_TYPE_LIMITS \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wtype-limits\"") +#define DISABLE_WARNING_ADDRESS \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Waddress\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") @@ -318,10 +322,14 @@ static inline int __coverity_check_and_return__(int condition) { *p = func(*p); \ } -/* When func() doesn't return the appropriate type, set variable to empty afterwards */ +/* When func() doesn't return the appropriate type, set variable to empty afterwards. + * The func() may be provided by a dynamically loaded shared library, hence add an assertion. */ #define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ static inline void func##p(type *p) { \ if (*p != (empty)) { \ + DISABLE_WARNING_ADDRESS; \ + assert(func); \ + REENABLE_WARNING; \ func(*p); \ *p = (empty); \ } \ -- 2.25.1