Fixed #8997 (False positive redundantAssignment when pointer is updated with +=)
This commit is contained in:
parent
f75c15af56
commit
5d10b57b04
|
@ -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 {
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue