From bd92363f790d99cfb9591a7595c1a3d41fd0b66d Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 4 Mar 2026 09:46:26 +0100 Subject: [PATCH] Only consider last NULL argument in varFuncNullUB Resolving a FP in which the expanded macro ensures that the last variadic argument is not NULL. --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 32dedf8f374..7d60410f9ca 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3557,7 +3557,7 @@ void CheckOther::checkVarFuncNullUB() for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { // Is NULL passed to a function? - if (Token::Match(tok,"[(,] NULL [,)]")) { + if (Token::Match(tok,"[(,] NULL )")) { // Locate function name in this function call. const Token *ftok = tok; int argnr = 1; diff --git a/test/testother.cpp b/test/testother.cpp index 53f14c2a31d..e502dcc5ff9 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11295,6 +11295,12 @@ class TestOther : public TestFixture { check("void a(char *p, ...);\n" "void b() { a(NULL, 2); }"); ASSERT_EQUALS("", errout_str()); + + checkP("extern const int sentinel;\n" + "void a(int, ...);\n" + "#define b(x, ...) a((x), __VA_ARGS__, &sentinel)\n" + "void c() { b(1, NULL); }"); + ASSERT_EQUALS("", errout_str()); } void checkCastIntToCharAndBack() { // #160