From 0e9fc7d480e7648ed79f0a65451b001c57309066 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:10:07 +0100 Subject: [PATCH 1/3] Update checknullpointer.cpp --- lib/checknullpointer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 0214eceedd1..30badc71b9c 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -310,7 +310,8 @@ void CheckNullPointer::nullPointerByDeRefAndCheck() return true; }; - std::vector tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings->library, scope->bodyStart, scope->bodyEnd, pred); + const Token* const start = scope->function->isConstructor() ? scope->function->token : scope->bodyStart; // Check initialization list + std::vector tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings->library, start, scope->bodyEnd, pred); for (const Token *tok : tokens) { const ValueFlow::Value *value = tok->getValue(0); From 19dd97cb4549f486a99de77ccff2f3dd2d46b929 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:11:34 +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 ee971fd44a8..501476ceb45 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -3742,6 +3742,15 @@ class TestNullPointer : public TestFixture { " return 1 ? 1 : *(int*)0 = 1;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check ("struct S {\n" // #13220 + " explicit S(int* p) : i(*p) {\n" + " if (p) {}\n" + " }\n" + " int i;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:2:29]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", + errout_str()); } void nullpointerDelete() { From e84e60d7c7b5bafd2672e63aef123f39cd14f676 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:27:22 +0100 Subject: [PATCH 3/3] Update checknullpointer.cpp --- lib/checknullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 30badc71b9c..0232ffcedf3 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -310,7 +310,7 @@ void CheckNullPointer::nullPointerByDeRefAndCheck() return true; }; - const Token* const start = scope->function->isConstructor() ? scope->function->token : scope->bodyStart; // Check initialization list + const Token* const start = (scope->function && scope->function->isConstructor()) ? scope->function->token : scope->bodyStart; // Check initialization list std::vector tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings->library, start, scope->bodyEnd, pred); for (const Token *tok : tokens) { const ValueFlow::Value *value = tok->getValue(0);