Clarify the code with Token::isUnaryOp and Token::isBinaryOp
This commit is contained in:
parent
c9a2071420
commit
d00e522856
|
@ -1387,7 +1387,7 @@ static bool canBeConst(const Variable *var)
|
||||||
if (!argVar|| (!argVar->isConst() && argVar->isReference()))
|
if (!argVar|| (!argVar->isConst() && argVar->isReference()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (parent->str() == "&" && !parent->astOperand2()) {
|
} else if (parent->isUnaryOp("&")) {
|
||||||
// TODO: check how pointer is used
|
// TODO: check how pointer is used
|
||||||
return false;
|
return false;
|
||||||
} else if (parent->isConstOp())
|
} else if (parent->isConstOp())
|
||||||
|
@ -1491,7 +1491,7 @@ void CheckOther::checkCharVariable()
|
||||||
signedCharArrayIndexError(tok);
|
signedCharArrayIndexError(tok);
|
||||||
if (portability && astIsUnknownSignChar(index) && index->getValueGE(0x80, mSettings))
|
if (portability && astIsUnknownSignChar(index) && index->getValueGE(0x80, mSettings))
|
||||||
unknownSignCharArrayIndexError(tok);
|
unknownSignCharArrayIndexError(tok);
|
||||||
} else if (warning && Token::Match(tok, "[&|^]") && tok->astOperand2() && tok->astOperand1()) {
|
} else if (warning && Token::Match(tok, "[&|^]") && tok->isBinaryOp()) {
|
||||||
bool warn = false;
|
bool warn = false;
|
||||||
if (astIsSignedChar(tok->astOperand1())) {
|
if (astIsSignedChar(tok->astOperand1())) {
|
||||||
const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, mSettings);
|
const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, mSettings);
|
||||||
|
@ -2485,30 +2485,21 @@ void CheckOther::checkRedundantPointerOp()
|
||||||
if (!mSettings->isEnabled(Settings::STYLE))
|
if (!mSettings->isEnabled(Settings::STYLE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
|
||||||
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "&") {
|
if (!tok->isUnaryOp("&") || !tok->astOperand1()->isUnaryOp("*"))
|
||||||
// bail out for logical AND operator
|
|
||||||
if (tok->astOperand2())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// pointer dereference
|
|
||||||
const Token *astTok = tok->astOperand1();
|
|
||||||
if (!astTok || astTok->str() != "*")
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// variable
|
// variable
|
||||||
const Token *varTok = astTok->astOperand1();
|
const Token *varTok = tok->astOperand1()->astOperand1();
|
||||||
if (!varTok || varTok->isExpandedMacro() || varTok->varId() == 0)
|
if (!varTok || varTok->isExpandedMacro())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Variable *var = symbolDatabase->getVariableFromVarId(varTok->varId());
|
const Variable *var = varTok->variable();
|
||||||
if (!var || !var->isPointer())
|
if (!var || !var->isPointer())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
redundantPointerOpError(tok, var->name(), false);
|
redundantPointerOpError(tok, var->name(), false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::redundantPointerOpError(const Token* tok, const std::string &varname, bool inconclusive)
|
void CheckOther::redundantPointerOpError(const Token* tok, const std::string &varname, bool inconclusive)
|
||||||
|
|
Loading…
Reference in New Issue