Fix FP redundantPointerOp with macro (#4061)

* Fix #10991 FN: Redundant pointer operation

* Fix FP redundantPointerOp

* Check for LValue

* Fix FP redundantPointerOp with macro

* Format
This commit is contained in:
chrchr-github 2022-04-29 13:23:50 +02:00 committed by GitHub
parent 0467ab1339
commit e7afb3045b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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;

View File

@ -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"