From 92cfb2e0520415223d2c0703cbe6ab440c29caba Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 11 Jul 2025 09:24:10 -0700 Subject: [PATCH] Coverity: Side effect in assertion 1. Modify AssertNotNull() to use the same pattern as AssertNull(). The macro assigns the pointer to a local variable and that is checked. Fixes CIDs: 537020 573008 573010 573011 573013 573014 573015 573016 573017 573018 573022 573023 573024 --- tests/api.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/api.c b/tests/api.c index cc78f801..ad40bc92 100644 --- a/tests/api.c +++ b/tests/api.c @@ -85,12 +85,15 @@ char* myoptarg = NULL; #define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE")) #define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE")) -#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL")) + +#define AssertNotNull(x) do { \ + PEDANTIC_EXTENSION void* _isNotNull = (void*)(x); \ + Assert(_isNotNull, ("%s is not null", #x), (#x " => NULL")); \ +} while (0) #define AssertNull(x) do { \ - PEDANTIC_EXTENSION void* _x = (void*)(x); \ - \ - Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \ + PEDANTIC_EXTENSION void* _isNull = (void*)(x); \ + Assert(!_isNull, ("%s is null", #x), (#x " => %p", _isNull)); \ } while(0) #define AssertInt(x, y, op, er) do { \