diff --git a/winpr/include/winpr/assert.h b/winpr/include/winpr/assert.h index b9257cd0b..1fb855469 100644 --- a/winpr/include/winpr/assert.h +++ b/winpr/include/winpr/assert.h @@ -30,29 +30,17 @@ #include #if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0) +#define winpr_internal_assert(cond, file, fkt, line) \ + do \ + { \ + if (!(cond)) \ + winpr_int_assert(#cond, (file), (fkt), (line)); \ + } while (0) + #ifdef __cplusplus extern "C" { #endif -#define WINPR_ASSERT(cond) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \ - WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \ - WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \ - WINPR_DO_PRAGMA(coverity compliance block \x28 deviate "CONSTANT_EXPRESSION_RESULT" \ - "WINPR_ASSERT" \x29 \ - \x28 deviate "NO_EFFECT" \ - "WINPR_ASSERT" \x29) \ - \ - if (!(cond)) \ - winpr_int_assert(#cond, __FILE__, __func__, __LINE__); \ - \ - WINPR_DO_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \ - "NO_EFFECT") \ - WINPR_PRAGMA_DIAG_POP \ - } while (0) static INLINE WINPR_NORETURN(void winpr_int_assert(const char* condstr, const char* file, const char* fkt, size_t line)) @@ -68,25 +56,29 @@ extern "C" #endif #else -#define WINPR_ASSERT(cond) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \ - WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \ - WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \ - WINPR_DO_PRAGMA(coverity compliance block \x28 deviate "CONSTANT_EXPRESSION_RESULT" \ - "WINPR_ASSERT" \x29 \ - \x28 deviate "NO_EFFECT" \ - "WINPR_ASSERT" \x29) \ - assert(cond); \ - \ - WINPR_DO_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \ - "NO_EFFECT") \ - WINPR_PRAGMA_DIAG_POP \ - } while (0) +#define winpr_internal_assert(cond, file, fkt, line) assert(cond) #endif +#define WINPR_ASSERT_AT(cond, file, fkt, line) \ + do \ + { \ + WINPR_PRAGMA_DIAG_PUSH \ + WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \ + WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \ + WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \ + WINPR_DO_COVERITY_PRAGMA(coverity compliance block \(deviate "CONSTANT_EXPRESSION_RESULT" \ + "WINPR_ASSERT" \) \ + \(deviate "NO_EFFECT" \ + "WINPR_ASSERT" \)) \ + \ + winpr_internal_assert((cond), (file), (fkt), (line)); \ + \ + WINPR_DO_COVERITY_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \ + "NO_EFFECT") \ + WINPR_PRAGMA_DIAG_POP \ + } while (0) +#define WINPR_ASSERT(cond) WINPR_ASSERT_AT((cond), __FILE__, __func__, __LINE__) + #ifdef __cplusplus extern "C" { diff --git a/winpr/include/winpr/platform.h b/winpr/include/winpr/platform.h index 2b860b505..987aa9f53 100644 --- a/winpr/include/winpr/platform.h +++ b/winpr/include/winpr/platform.h @@ -32,6 +32,12 @@ #define WINPR_DO_PRAGMA(x) __pragma(#x) #endif +#if !defined(__COVERITY__) +#define WINPR_DO_COVERITY_PRAGMA(x) +#else +#define WINPR_DO_COVERITY_PRAGMA(x) WINPR_DO_PRAGMA(x) +#endif + #if defined(__GNUC__) #define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg) #elif defined(__clang__)