Fix 10988: FP: Regression, uninitvar (#4037)

This commit is contained in:
Paul Fultz II 2022-04-21 12:29:38 -05:00 committed by GitHub
parent ce35a6c975
commit 3feecc51d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -1574,6 +1574,8 @@ static ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* se
if (indirect > 0 && tok->astParent()) {
if (Token::Match(tok->astParent(), "%assign%") && astIsRhs(tok))
return ExprUsage::NotUsed;
if (tok->astParent()->isConstOp())
return ExprUsage::NotUsed;
if (tok->astParent()->isCast())
return ExprUsage::NotUsed;
}

View File

@ -5247,6 +5247,44 @@ private:
" std::memcpy(&dest, &src, 1);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: &src\n", errout.str());
// #10988
valueFlowUninit("void f(const void* ptr, bool* result) {\n"
" int dummy;\n"
" *result = (&dummy < ptr);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct A {\n"
" int x;\n"
"};\n"
"void f() {\n"
" A a;\n"
" A* p = &a;\n"
" p->x = 1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct A {\n"
" int x;\n"
"};\n"
"void g(const int&);\n"
"void f() {\n"
" A a;\n"
" g(a.x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: a.x\n", errout.str());
valueFlowUninit("struct A {\n"
" int x;\n"
"};\n"
"void g(const int&);\n"
"void f() {\n"
" A a;\n"
" A* p = &a;\n"
" g(p->x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout.str());
}
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value