From e7afb3045b511a67c60e06c2f33f1d92128de6e1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 29 Apr 2022 13:23:50 +0200 Subject: [PATCH] Fix FP redundantPointerOp with macro (#4061) * Fix #10991 FN: Redundant pointer operation * Fix FP redundantPointerOp * Check for LValue * Fix FP redundantPointerOp with macro * Format --- lib/checkother.cpp | 9 ++++++++- test/testother.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a737b328a..7c542dc53 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2951,9 +2951,16 @@ void CheckOther::checkRedundantPointerOp() // variable const Token *varTok = tok->astOperand1()->astOperand1(); - if (!varTok || varTok->isExpandedMacro() || (!addressOfDeref && varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue)) + if (!varTok || varTok->isExpandedMacro()) continue; + if (!addressOfDeref) { // dereference of address + if (tok->isExpandedMacro()) + continue; + if (varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue) + continue; + } + const Variable *var = varTok->variable(); if (!var || (addressOfDeref && !var->isPointer())) continue; diff --git a/test/testother.cpp b/test/testother.cpp index d753c7032..541a2b6f0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8777,6 +8777,12 @@ private: check("void f(int**& p) {}\n", nullptr, false, true); ASSERT_EQUALS("", errout.str()); + checkP("#define RESTORE(ORIG, COPY) { *ORIG = *COPY; }\n" + "void f(int* p, int i) {\n" + " RESTORE(p, &i);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // no warning for bitwise AND check("void f(const int *b) {\n" " int x = 0x20 & *b;\n"