valueFlowForward: better handling of sizeof() in rhs in assignments

This commit is contained in:
Daniel Marjamäki 2017-04-29 08:25:55 +02:00
parent ddfd4c6348
commit 980ca39fe2
2 changed files with 15 additions and 4 deletions

View File

@ -1005,8 +1005,8 @@ static void valueFlowReverse(TokenList *tokenlist,
break;
}
// skip sizeof..
if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "typeof|sizeof ("))
// skip sizeof etc..
if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "sizeof|typeof|typeid ("))
tok2 = tok2->link();
// goto label
@ -1307,7 +1307,8 @@ static bool valueFlowForward(Token * const startToken,
return false;
}
if (Token::Match(tok2, "sizeof|typeof|typeid ("))
// Skip sizeof etc
else if (Token::Match(tok2, "sizeof|typeof|typeid ("))
tok2 = tok2->linkAt(1);
else if (Token::simpleMatch(tok2, "else {")) {
@ -1635,7 +1636,7 @@ static bool valueFlowForward(Token * const startToken,
else if (tok2->varId() == varid) {
// bailout: assignment
if (Token::Match(tok2->previous(), "!!* %name% %op%") && tok2->next()->isAssignmentOp()) {
if (Token::Match(tok2->previous(), "!!* %name% %assign%")) {
// simplify rhs
for (Token *tok3 = tok2->tokAt(2); tok3; tok3 = tok3->next()) {
if (tok3->varId() == varid) {
@ -1644,6 +1645,9 @@ static bool valueFlowForward(Token * const startToken,
setTokenValue(tok3, *it, settings);
} else if (Token::Match(tok3, "++|--|?|:|;"))
break;
// Skip sizeof etc
else if (Token::Match(tok3, "sizeof|typeof|typeid ("))
tok3 = tok3->linkAt(1);
}
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "assignment of " + tok2->str());

View File

@ -2422,6 +2422,13 @@ private:
"}";
values = tokenValues(code, "c .");
ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
code = "void f() {\n"
" int **x;\n"
" y += 10;\n"
" x = dostuff(sizeof(*x)*y);\n"
"}";
ASSERT_EQUALS(0U, tokenValues(code, "x )").size());
}
};