Skip to content

Commit

Permalink
Fix #12858 FP knownConditionTrueFalse with switch in try/catch in sub…
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
chrchr-github committed Jun 27, 2024
1 parent bd536d3 commit 75b609e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ namespace {
} else if (Token::simpleMatch(tok, "switch (")) {
if (updateRecursive(tok->next()->astOperand2()) == Progress::Break)
return Break();
return Break();
return updateScope(tok->next()->link()->next()->link());
} else if (Token* callTok = callExpr(tok)) {
// TODO: Dont traverse tokens a second time
if (start != callTok && tok != callTok && updateRecursive(callTok->astOperand1()) == Progress::Break)
Expand Down
20 changes: 20 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4631,6 +4631,26 @@ class TestCondition : public TestFixture {
" return;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("int h();\n"
"bool g() {\n"
" bool b{};\n"
" try {\n"
" int x = h();\n"
" switch (x) {\n"
" default:\n"
" b = true;\n"
" }\n"
" }\n"
" catch (...) {\n"
" b = false;\n"
" }\n"
" return b;\n"
"}\n"
"void f() {\n"
" if (g()) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueSymbolic()
Expand Down
3 changes: 2 additions & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3154,7 +3154,8 @@ class TestNullPointer : public TestFixture {
" break;\n"
" };\n"
"}");
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:7]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred.\n",
errout_str());

// #4118 - second if
check("void f(char *p) {\n"
Expand Down
2 changes: 1 addition & 1 deletion test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ class TestValueFlow : public TestFixture {
" case A: v = x; break;\n" // <- x is not 34
" }\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 8U, 34));
TODO_ASSERT_EQUALS(false, true, testValueOfX(code, 8U, 34));

// while/for
code = "void f() {\n" // #6138
Expand Down

0 comments on commit 75b609e

Please sign in to comment.