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
pull/817/head
John Safranek 2025-07-11 09:24:10 -07:00
parent dd377d6d53
commit 92cfb2e052
1 changed files with 7 additions and 4 deletions

View File

@ -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 { \