Fix #11492 FP uninitvar with try/catch (#4711)

This commit is contained in:
chrchr-github 2023-01-14 20:14:38 +01:00 committed by GitHub
parent 7bbdc95f25
commit a79dff15ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -770,7 +770,7 @@ struct ForwardTraversal {
tryTraversal.updateRange(tok->next(), endBlock, depth - 1); tryTraversal.updateRange(tok->next(), endBlock, depth - 1);
bool bail = tryTraversal.actions.isModified(); bool bail = tryTraversal.actions.isModified();
if (bail) if (bail)
analyzer->lowerToPossible(); return Break();
while (Token::simpleMatch(endBlock, "} catch (")) { while (Token::simpleMatch(endBlock, "} catch (")) {
Token* endCatch = endBlock->linkAt(2); Token* endCatch = endBlock->linkAt(2);

View File

@ -265,6 +265,7 @@ private:
TEST_CASE(moveCallback); TEST_CASE(moveCallback);
TEST_CASE(moveClassVariable); TEST_CASE(moveClassVariable);
TEST_CASE(forwardAndUsed); TEST_CASE(forwardAndUsed);
TEST_CASE(moveAndReference);
TEST_CASE(funcArgNamesDifferent); TEST_CASE(funcArgNamesDifferent);
TEST_CASE(funcArgOrderDifferent); TEST_CASE(funcArgOrderDifferent);
@ -10193,6 +10194,18 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (warning) Access of forwarded variable 't'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (warning) Access of forwarded variable 't'.\n", errout.str());
} }
void moveAndReference() { // #9791
check("void g(std::string&&);\n"
"void h(const std::string&);\n"
"void f() {\n"
" std::string s;\n"
" const std::string& r = s;\n"
" g(std::move(s));\n"
" h(r);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'r'.\n", errout.str());
}
void funcArgNamesDifferent() { void funcArgNamesDifferent() {
check("void func1(int a, int b, int c);\n" check("void func1(int a, int b, int c);\n"
"void func1(int a, int b, int c) { }\n" "void func1(int a, int b, int c) { }\n"

View File

@ -5407,6 +5407,18 @@ private:
" (void)p[i];\n" " (void)p[i];\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #11492
valueFlowUninit("void f() {\n"
" int i;\n"
" try {\n"
" i = 0;\n"
" }\n"
" catch (...) {\n"
" if (i) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value