Fixed #3597 (Errors in evaluation of chained assignment operators)
This commit is contained in:
parent
1e7a5f57c5
commit
d5442280b1
|
@ -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())) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue