Fix 10988: FP: Regression, uninitvar (#4037)
This commit is contained in:
parent
ce35a6c975
commit
3feecc51d6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue