From 20e63bcaf0af1a03970955145afec6066c99f0c1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 7 May 2026 11:34:23 +0200 Subject: [PATCH 1/2] Update testnullpointer.cpp --- test/testnullpointer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 04d2f61fc0c..c025d7462d4 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4830,6 +4830,15 @@ class TestNullPointer : public TestFixture { "[test.cpp:5:20]: note: Assignment 'f=fopen(notexist,t)', assigned value is 0\n" "[test.cpp:6:8]: note: Calling function foo, 1st argument is null\n" "[test.cpp:2:13]: note: Dereferencing argument f that is null\n", errout_str()); + + ctu("void g(std::optional& o) {\n" // #14728 + " *o = 1;\n" + "}\n" + "void f() {\n" + " std::optional x = 0;\n" + " g(x);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } }; From 046e0da96c2db479aabd1d31fce1d8bcdfaa9c6c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 7 May 2026 11:35:54 +0200 Subject: [PATCH 2/2] Update checknullpointer.cpp --- lib/checknullpointer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 02c5cd8c812..beb9d5d77a3 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -187,6 +187,8 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set // declaration of function pointer if (tok->variable() && tok->variable()->nameToken() == tok) return false; + if ((tok->valueType() && tok->valueType()->pointer == 0) && !astIsIterator(tok) && !astIsSmartPointer(tok)) + return false; if (!addressOf) return true; }