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
|
// uncertain
|
||||||
bool unknown = _settings->inconclusive;
|
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;
|
break;
|
||||||
} else if (Token::simpleMatch(tok1->tokAt(-2), "* )") &&
|
} else if (Token::simpleMatch(tok1->tokAt(-2), "* )") &&
|
||||||
Token::Match(tok1->linkAt(-1)->tokAt(-2), "%varid% = (", tok1->varId())) {
|
Token::Match(tok1->linkAt(-1)->tokAt(-2), "%varid% = (", tok1->varId())) {
|
||||||
|
|
|
@ -653,6 +653,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
check("void foo(struct ABC *abc)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" abc = abc ? abc->next : 0;\n"
|
" abc = abc ? abc->next : 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue