From 5d10b57b04eb1c0123ad2c682dc49c964f68ce08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 31 May 2019 12:24:13 +0200 Subject: [PATCH] Fixed #8997 (False positive redundantAssignment when pointer is updated with +=) --- lib/astutils.cpp | 2 ++ test/testother.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) 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() {