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
20 changes: 20 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3918,3 +3918,23 @@ const Token *skipUnreachableBranch(const Token *tok)

return tok;
}

bool isEscapeKeyword(const Token *tok, const Settings &settings)
{
if (!tok)
return false;

if (tok->str() == "return")
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
return true;

if (!tok->isCpp())
return false;

if (tok->str() == "throw")
return true;

if (settings.standards.cpp < Standards::CPP20)
return false;

return tok->str() == "co_return";
}
2 changes: 2 additions & 0 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,6 @@ bool isUnreachableOperand(const Token *tok);

const Token *skipUnreachableBranch(const Token *tok);

bool isEscapeKeyword(const Token *tok, const Settings &settings);

#endif // astutilsH
2 changes: 1 addition & 1 deletion lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace {
// If we are in a loop then jump to the end
if (out)
*out = loopEnds.back();
} else if (Token::Match(tok, "return|throw")) {
} else if (isEscapeKeyword(tok, settings)) {
traverseRecursive(tok->astOperand2(), f, traverseUnknown);
traverseRecursive(tok->astOperand1(), f, traverseUnknown);
return Break(Analyzer::Terminate::Escape);
Expand Down
13 changes: 13 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class TestNullPointer : public TestFixture {
TEST_CASE(nullpointer106); // #13682
TEST_CASE(nullpointer107); // #13682 (FP/FN cases around guards that depend on the pointer indirectly)
TEST_CASE(nullpointer108);
TEST_CASE(nullpointer109);
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
Expand Down Expand Up @@ -3115,6 +3116,18 @@ class TestNullPointer : public TestFixture {
ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: r [nullPointer]\n", errout_str());
}

void nullpointer109()
{
check("boost::asio::awaitable<int> test()\n"
"{\n"
" const auto *s = getStr();\n"
" if(!s) co_return int{1};\n"
" std::print(\"{}\",*s);\n"
" co_return int{9};\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"
Expand Down
Loading