From b3e95d366ae1fd9b80f95fe1ba0962ef09cadb70 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 09:23:49 +0100 Subject: [PATCH 1/5] 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 5c2e64e9a6c..13a803bf721 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -470,7 +470,7 @@ void CheckNullPointerImpl::nullPointerError(const Token *tok, const std::string errmsg = "$symbol:" + varname + '\n' + errmsg + ": $symbol"; reportError(std::move(errorPath), - value->isKnown() ? Severity::error : Severity::warning, + value->isKnown() && !value->conditional ? Severity::error : Severity::warning, id.c_str(), errmsg, CWE_NULL_POINTER_DEREFERENCE, inconclusive || value->isInconclusive() ? Certainty::inconclusive : Certainty::normal); From 3aa29a187aedde01ef6755a42c6ad15c1256ca7d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 09:25:53 +0100 Subject: [PATCH 2/5] Update testnullpointer.cpp --- test/testnullpointer.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index ca5c183c911..e0cf9992be3 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -173,6 +173,7 @@ class TestNullPointer : public TestFixture { TEST_CASE(nullpointerSmartPointer); TEST_CASE(nullpointerOutOfMemory); TEST_CASE(nullpointerOutOfResources); + TEST_CASE(nullpointerErrorPath); TEST_CASE(functioncall); TEST_CASE(functioncalllibrary); // use Library to parse function call TEST_CASE(functioncallDefaultArguments); @@ -2488,7 +2489,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer78() // #7802 @@ -4100,10 +4101,10 @@ class TestNullPointer : public TestFixture { " foo(p == s2);\n" " foo(p == s3);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:8:9]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (warning) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:5:15]: (warning) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:7:9]: (warning) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:8:9]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f(std::string s1, const std::string& s2, const std::string* s3) {\n" " void* p = 0;\n" @@ -4586,6 +4587,24 @@ class TestNullPointer : public TestFixture { errout_str()); } + void nullpointerErrorPath() { + setMultiline(); + Settings s = settings; + s.templateLocation = "{file}:{line}:note:{info}\n"; + check("int f(bool b) {\n" + " int* p = nullptr;\n" + " if (b)\n" + " return 0;\n" + " return *p;\n" + "}\n", s); + ASSERT_EQUALS( + "[test.cpp:5:13]: warning: Null pointer dereference: p [nullPointer]\n" + "[test.cpp:2:14]: note: Assignment 'p=nullptr', assigned value is 0\n" + "[test.cpp:3:9]: note: Assuming condition is false\n" + "[test.cpp:5:13]: note: Null pointer dereference\n", + errout_str()); + } + void functioncalllibrary() { SimpleTokenizer tokenizer(settingsDefault,*this,false); const char code[] = "void f() { int a,b,c; x(a,b,c); }\n"; From 5394c1d7e60f9a66ac21d6754ebd5a3432af951d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:46:38 +0100 Subject: [PATCH 3/5] Update checknullpointer.cpp [skip ci] --- lib/checknullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 13a803bf721..2251d50e1e7 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -454,7 +454,7 @@ void CheckNullPointerImpl::nullPointerError(const Token *tok, const std::string } else if (value->defaultArg) { reportError(std::move(errorPath), Severity::warning, "nullPointerDefaultArg", errmsgdefarg, CWE_NULL_POINTER_DEREFERENCE, inconclusive || value->isInconclusive() ? Certainty::inconclusive : Certainty::normal); } else { - std::string errmsg = std::string(value->isKnown() ? "Null" : "Possible null") + " pointer dereference"; + std::string errmsg = std::string(value->isKnown() && !value->conditional ? "Null" : "Possible null") + " pointer dereference"; std::string id = "nullPointer"; if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { From ddb3eafdf26eae3993e63d17db0ebb16402f90cf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:49:40 +0100 Subject: [PATCH 4/5] Update testnullpointer.cpp --- test/testnullpointer.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index e0cf9992be3..4f369ab16f5 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2489,7 +2489,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4:10]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer78() // #7802 @@ -4101,10 +4101,10 @@ class TestNullPointer : public TestFixture { " foo(p == s2);\n" " foo(p == s3);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4:15]: (warning) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:5:15]: (warning) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:7:9]: (warning) Null pointer dereference: p [nullPointer]\n" - "[test.cpp:8:9]: (warning) Null pointer dereference: p [nullPointer]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (warning) Possible null pointer dereference: p [nullPointer]\n" + "[test.cpp:5:15]: (warning) Possible null pointer dereference: p [nullPointer]\n" + "[test.cpp:7:9]: (warning) Possible null pointer dereference: p [nullPointer]\n" + "[test.cpp:8:9]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); check("void f(std::string s1, const std::string& s2, const std::string* s3) {\n" " void* p = 0;\n" @@ -4589,8 +4589,7 @@ class TestNullPointer : public TestFixture { void nullpointerErrorPath() { setMultiline(); - Settings s = settings; - s.templateLocation = "{file}:{line}:note:{info}\n"; + check("int f(bool b) {\n" " int* p = nullptr;\n" " if (b)\n" @@ -4598,7 +4597,7 @@ class TestNullPointer : public TestFixture { " return *p;\n" "}\n", s); ASSERT_EQUALS( - "[test.cpp:5:13]: warning: Null pointer dereference: p [nullPointer]\n" + "[test.cpp:5:13]: warning: Possible null pointer dereference: p [nullPointer]\n" "[test.cpp:2:14]: note: Assignment 'p=nullptr', assigned value is 0\n" "[test.cpp:3:9]: note: Assuming condition is false\n" "[test.cpp:5:13]: note: Null pointer dereference\n", From 09eea1c174b3f6cfddc4b34dcbd30164895b950c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:56:14 +0100 Subject: [PATCH 5/5] Update testnullpointer.cpp --- test/testnullpointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 4f369ab16f5..741f54ba76a 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4595,7 +4595,7 @@ class TestNullPointer : public TestFixture { " if (b)\n" " return 0;\n" " return *p;\n" - "}\n", s); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:13]: warning: Possible null pointer dereference: p [nullPointer]\n" "[test.cpp:2:14]: note: Assignment 'p=nullptr', assigned value is 0\n"