Skip to content

Commit fbf35b8

Browse files
authored
Fix #14573 Only consider last NULL argument in varFuncNullUB (#8297)
Resolving a FP in which the expanded macro ensures that the last variadic argument is not NULL.
1 parent 391dd83 commit fbf35b8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ void CheckOther::checkVarFuncNullUB()
35573557
for (const Scope * scope : symbolDatabase->functionScopes) {
35583558
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
35593559
// Is NULL passed to a function?
3560-
if (Token::Match(tok,"[(,] NULL [,)]")) {
3560+
if (Token::Match(tok,"[(,] NULL )")) {
35613561
// Locate function name in this function call.
35623562
const Token *ftok = tok;
35633563
int argnr = 1;

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11309,6 +11309,12 @@ class TestOther : public TestFixture {
1130911309
check("void a(char *p, ...);\n"
1131011310
"void b() { a(NULL, 2); }");
1131111311
ASSERT_EQUALS("", errout_str());
11312+
11313+
checkP("extern const int sentinel;\n"
11314+
"void a(int, ...);\n"
11315+
"#define b(x, ...) a((x), __VA_ARGS__, &sentinel)\n"
11316+
"void c() { b(1, NULL); }");
11317+
ASSERT_EQUALS("", errout_str());
1131211318
}
1131311319

1131411320
void checkCastIntToCharAndBack() { // #160

0 commit comments

Comments
 (0)