* Skip redundant pointer op * Fix #11018 FP uninitvar with redundant pointer op * Format
This commit is contained in:
parent
aebc080c0f
commit
adba751217
|
@ -2241,6 +2241,18 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
|
||||||
if (Token::Match(tok2->astParent(), "++|--"))
|
if (Token::Match(tok2->astParent(), "++|--"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
auto skipRedundantPtrOp = [](const Token* tok, const Token* parent) {
|
||||||
|
const Token* gparent = parent ? parent->astParent() : nullptr;
|
||||||
|
while (parent && gparent && ((parent->isUnaryOp("*") && gparent->isUnaryOp("&")) || ((parent->isUnaryOp("&") && gparent->isUnaryOp("*"))))) {
|
||||||
|
tok = gparent;
|
||||||
|
parent = gparent->astParent();
|
||||||
|
if (parent)
|
||||||
|
gparent = parent->astParent();
|
||||||
|
}
|
||||||
|
return tok;
|
||||||
|
};
|
||||||
|
tok2 = skipRedundantPtrOp(tok2, tok2->astParent());
|
||||||
|
|
||||||
if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) {
|
if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) {
|
||||||
if (tok2 == tok2->astParent()->astOperand1())
|
if (tok2 == tok2->astParent()->astOperand1())
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6373,6 +6373,17 @@ private:
|
||||||
" x.push_back(a);\n"
|
" x.push_back(a);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: a\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("struct S { struct T { int* p; } t[2]; };\n" // #11018
|
||||||
|
"void f() {\n"
|
||||||
|
" S s;\n"
|
||||||
|
" *&s.t[0].p = 0;\n"
|
||||||
|
"}\n"
|
||||||
|
"void g() {\n"
|
||||||
|
" S s;\n"
|
||||||
|
" ((*&(*&s.t[0].p))) = 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu_(const char* file, int line, const char code[]) {
|
void ctu_(const char* file, int line, const char code[]) {
|
||||||
|
|
Loading…
Reference in New Issue