Fixed #8997 (False positive redundantAssignment when pointer is updated with +=)

This commit is contained in:
Daniel Marjamäki 2019-05-31 12:24:13 +02:00
parent f75c15af56
commit 5d10b57b04
2 changed files with 12 additions and 0 deletions

View File

@ -1283,6 +1283,8 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
if (reassign) if (reassign)
return Result(Result::Type::WRITE, parent->astParent()); return Result(Result::Type::WRITE, parent->astParent());
return Result(Result::Type::READ); return Result(Result::Type::READ);
} else if (mWhat == What::Reassign && parent->valueType() && parent->valueType()->pointer && Token::Match(parent->astParent(), "%assign%") && parent == parent->astParent()->astOperand1()) {
return Result(Result::Type::READ);
} else if (Token::Match(parent->astParent(), "%assign%") && !parent->astParent()->astParent() && parent == parent->astParent()->astOperand1()) { } else if (Token::Match(parent->astParent(), "%assign%") && !parent->astParent()->astParent() && parent == parent->astParent()->astOperand1()) {
continue; continue;
} else { } else {

View File

@ -6138,6 +6138,16 @@ private:
" *x = 32;\n" " *x = 32;\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #8997
check("void f() {\n"
" char x[2];\n"
" char* p = x;\n"
" *p = 1;\n"
" p += 1;\n"
" *p = 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void redundantVarAssignment_pointer_parameter() { void redundantVarAssignment_pointer_parameter() {