Skip to content

Commit 92cfb2e

Browse files
committed
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
1 parent dd377d6 commit 92cfb2e

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tests/api.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ char* myoptarg = NULL;
8585

8686
#define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE"))
8787
#define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE"))
88-
#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
88+
89+
#define AssertNotNull(x) do { \
90+
PEDANTIC_EXTENSION void* _isNotNull = (void*)(x); \
91+
Assert(_isNotNull, ("%s is not null", #x), (#x " => NULL")); \
92+
} while (0)
8993

9094
#define AssertNull(x) do { \
91-
PEDANTIC_EXTENSION void* _x = (void*)(x); \
92-
\
93-
Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
95+
PEDANTIC_EXTENSION void* _isNull = (void*)(x); \
96+
Assert(!_isNull, ("%s is null", #x), (#x " => %p", _isNull)); \
9497
} while(0)
9598

9699
#define AssertInt(x, y, op, er) do { \

0 commit comments

Comments
 (0)