From 0bf9b2577a576ff9aa838410b85bcd8a1c582d4c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:41:22 +0100 Subject: [PATCH 1/3] Update checknullpointer.cpp --- lib/checknullpointer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 0232ffcedf3..4b6a21f82f9 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -223,10 +223,10 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set return true; // std::string dereferences nullpointers - if (Token::Match(parent->tokAt(-3), "std :: string|wstring (|{ %name% )|}")) + if (Token::Match(parent->tokAt(-3), "std :: string|wstring (|{")) return true; - if (Token::Match(parent->previous(), "%name% (|{ %name% )|}")) { - const Variable* var = tok->tokAt(-2)->variable(); + if (Token::Match(parent->previous(), "%name% (|{")) { + const Variable* var = parent->previous()->variable(); if (var && !var->isPointer() && !var->isArray() && var->isStlStringType()) return true; } From 09c92f0458ece12d82d56ce703b3434919e61628 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:42:36 +0100 Subject: [PATCH 2/3] Update testnullpointer.cpp --- test/testnullpointer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 501476ceb45..a5933eda08b 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -3944,6 +3944,15 @@ class TestNullPointer : public TestFixture { "void f() { std::string s = g(0L); }\n"); ASSERT_EQUALS("[test.cpp:2:29]: (error) Null pointer dereference: g(0L) [nullPointer]\n", errout_str()); + + check("const char* g() { return nullptr; }\n" // #14098 + "std::string f() {\n" + " std::string s{ g() };\n" + " return s + std::string(g());\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:21]: (error) Null pointer dereference: g() [nullPointer]\n" + "[test.cpp:4:29]: (error) Null pointer dereference: g() [nullPointer]\n", + errout_str()); } void nullpointerStdStream() { From 6df17ac81c54250909a6921fa6f3f8613317d154 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:52:42 +0100 Subject: [PATCH 3/3] Format [skip ci] --- test/testnullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index a5933eda08b..1eb01edfcce 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -3944,7 +3944,7 @@ class TestNullPointer : public TestFixture { "void f() { std::string s = g(0L); }\n"); ASSERT_EQUALS("[test.cpp:2:29]: (error) Null pointer dereference: g(0L) [nullPointer]\n", errout_str()); - + check("const char* g() { return nullptr; }\n" // #14098 "std::string f() {\n" " std::string s{ g() };\n"