Fixed pattern matching in isVariableChanged() to handle normal token list better

This commit is contained in:
Daniel Marjamäki 2019-03-01 13:23:03 +01:00
parent 24739dc5f2
commit 845c407ab7
2 changed files with 16 additions and 4 deletions

View File

@ -917,10 +917,14 @@ bool isVariableChanged(const Token *start, const Token *end, const unsigned int
continue;
}
if (Token::Match(tok, "%name% %assign%|++|--"))
const Token *tok2 = tok;
while (Token::simpleMatch(tok2->astParent(), "*"))
tok2 = tok2->astParent();
if (Token::Match(tok2->astParent(), "++|--"))
return true;
if (Token::Match(tok->previous(), "++|-- %name%"))
if (tok2->astParent() && tok2->astParent()->isAssignmentOp() && tok2 == tok2->astParent()->astOperand1())
return true;
if (isLikelyStreamRead(cpp, tok->previous()))

View File

@ -3361,16 +3361,24 @@ private:
ASSERT_EQUALS(true, values.front().isPossible() || values.back().isPossible());
ASSERT_EQUALS(true, values.front().intvalue == 0 || values.back().intvalue == 0);
code = "void f() {\n"
code = "void f() {\n" // sqlite
" int szHdr;\n"
" idx = (A<0x80) ? (szHdr = 0) : dostuff(A, (int *)&(szHdr));\n"
" d = szHdr;\n"
" d = szHdr;\n" // szHdr can be 0.
"}";
values = tokenValues(code, "szHdr ; }");
TODO_ASSERT_EQUALS(1, 0, values.size());
if (values.size() == 1) {
ASSERT_EQUALS(false, values.front().isUninitValue());
}
code = "void f () {\n"
" int szHdr;\n"
" idx = ((aKey<0x80) ? ((szHdr)=aKey), 1 : sqlite3GetVarint32(&(szHdr)));\n"
" d = szHdr;\n"
"}";
values = tokenValues(code, "szHdr ; }");
ASSERT_EQUALS(0, values.size());
}
void valueFlowTerminatingCond() {