Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& o) {\n" // #14728
" *o = 1;\n"
"}\n"
"void f() {\n"
" std::optional<int> x = 0;\n"
" g(x);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}
};

Expand Down
Loading