Fixed #3597 (Errors in evaluation of chained assignment operators)

This commit is contained in:
Daniel Marjamäki 2012-05-01 07:06:14 +02:00
parent 1e7a5f57c5
commit d5442280b1
2 changed files with 26 additions and 1 deletions

View File

@ -863,7 +863,24 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
// uncertain
bool unknown = _settings->inconclusive;
if (Token::Match(tok1->tokAt(-2), "%varid% = %varid% .", varid)) {
// reassign : is the pointer reassigned like this:
// tok = tok->next();
bool reassign = false;
if (Token::Match(tok1->previous(), "= %varid% .", varid)) {
const Token *back = tok1->tokAt(-2);
while (back) {
if (back->varId() == varid) {
reassign = true;
break;
}
if (Token::Match(back, "[{};,(]")) {
break;
}
back = back->previous();
}
}
if (reassign) {
break;
} else if (Token::simpleMatch(tok1->tokAt(-2), "* )") &&
Token::Match(tok1->linkAt(-1)->tokAt(-2), "%varid% = (", tok1->varId())) {

View File

@ -653,6 +653,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(x *p)\n"
"{\n"
" p = *p2 = p->next;\n"
" if (!p)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(struct ABC *abc)\n"
"{\n"
" abc = abc ? abc->next : 0;\n"