diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 18cbbed1b..5035332ed 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1283,6 +1283,8 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const if (reassign) return Result(Result::Type::WRITE, parent->astParent()); 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()) { continue; } else { diff --git a/test/testother.cpp b/test/testother.cpp index c6c9228b6..1031db170 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6138,6 +6138,16 @@ private: " *x = 32;\n" "}"); 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() {