move setting flags checks out of for loops, make them const.
This commit is contained in:
parent
3b84706088
commit
eedcb6abcb
|
@ -118,8 +118,8 @@ static bool variableIsUsedInScope(const Token* start, unsigned int varId, const
|
|||
|
||||
void CheckAutoVariables::assignFunctionArg()
|
||||
{
|
||||
bool style = _settings->isEnabled("style");
|
||||
bool warning = _settings->isEnabled("warning");
|
||||
const bool style = _settings->isEnabled("style");
|
||||
const bool warning = _settings->isEnabled("warning");
|
||||
if (!style && !warning)
|
||||
return;
|
||||
|
||||
|
|
|
@ -979,6 +979,8 @@ static const Scope* findFunctionOf(const Scope* scope)
|
|||
|
||||
void CheckClass::checkMemset()
|
||||
{
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
|
@ -1052,7 +1054,7 @@ void CheckClass::checkMemset()
|
|||
std::list<const Scope *> parsedTypes;
|
||||
checkMemsetType(scope, tok->tokAt(2), tok->variable()->typeScope(), true, parsedTypes);
|
||||
|
||||
if (tok->variable()->typeScope()->numConstructors > 0 && _settings->isEnabled("warning"))
|
||||
if (tok->variable()->typeScope()->numConstructors > 0 && printWarnings)
|
||||
mallocOnClassWarning(tok, tok->strAt(2), tok->variable()->typeScope()->classDef);
|
||||
}
|
||||
}
|
||||
|
@ -1061,6 +1063,8 @@ void CheckClass::checkMemset()
|
|||
|
||||
void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type, bool allocation, std::list<const Scope *> parsedTypes)
|
||||
{
|
||||
const bool printPortability = _settings->isEnabled("portability");
|
||||
|
||||
// If type has been checked there is no need to check it again
|
||||
if (std::find(parsedTypes.begin(), parsedTypes.end(), type) != parsedTypes.end())
|
||||
return;
|
||||
|
@ -1110,7 +1114,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
|||
checkMemsetType(start, tok, typeScope, allocation, parsedTypes);
|
||||
|
||||
// check for float
|
||||
else if (tok->str() == "memset" && var->isFloatingType() && _settings->isEnabled("portability"))
|
||||
else if (tok->str() == "memset" && var->isFloatingType() && printPortability)
|
||||
memsetErrorFloat(tok, type->classDef->str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -584,8 +584,8 @@ template<class T> static T getvalue(const int test, const T value1, const T valu
|
|||
|
||||
void CheckCondition::checkIncorrectLogicOperator()
|
||||
{
|
||||
bool style = _settings->isEnabled("style");
|
||||
bool warning = _settings->isEnabled("warning");
|
||||
const bool style = _settings->isEnabled("style");
|
||||
const bool warning = _settings->isEnabled("warning");
|
||||
if (!style && !warning)
|
||||
return;
|
||||
|
||||
|
|
|
@ -100,6 +100,8 @@ void CheckIO::checkFileUsage()
|
|||
};
|
||||
static const std::set<std::string> whitelist(_whitelist, _whitelist + sizeof(_whitelist)/sizeof(*_whitelist));
|
||||
const bool windows = _settings->isWindowsPlatform();
|
||||
const bool printPortability = _settings->isEnabled("portability");
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
std::map<unsigned int, Filepointer> filepointers;
|
||||
|
||||
|
@ -179,7 +181,7 @@ void CheckIO::checkFileUsage()
|
|||
operation = Filepointer::OPEN;
|
||||
} else if ((tok->str() == "rewind" || tok->str() == "fseek" || tok->str() == "fsetpos" || tok->str() == "fflush") ||
|
||||
(windows && tok->str() == "_fseeki64")) {
|
||||
if (_settings->isEnabled("portability") && tok->str() == "fflush") {
|
||||
if (printPortability && tok->str() == "fflush") {
|
||||
fileTok = tok->tokAt(2);
|
||||
if (fileTok) {
|
||||
if (fileTok->str() == "stdin")
|
||||
|
@ -270,7 +272,7 @@ void CheckIO::checkFileUsage()
|
|||
case Filepointer::POSITIONING:
|
||||
if (f.mode == CLOSED)
|
||||
useClosedFileError(tok);
|
||||
else if (f.append_mode == Filepointer::APPEND && tok->str() != "fflush" && _settings->isEnabled("warning"))
|
||||
else if (f.append_mode == Filepointer::APPEND && tok->str() != "fflush" && printWarnings)
|
||||
seekOnAppendedFileError(tok);
|
||||
break;
|
||||
case Filepointer::READ:
|
||||
|
|
|
@ -308,6 +308,8 @@ void CheckNullPointer::nullPointerLinkedList()
|
|||
|
||||
void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||
{
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
const Variable *var = tok->variable();
|
||||
if (!var || !var->isPointer() || tok == var->nameToken())
|
||||
|
@ -336,7 +338,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
|||
if (std::find(varlist.begin(), varlist.end(), tok) != varlist.end()) {
|
||||
if (value->condition == nullptr)
|
||||
nullPointerError(tok, tok->str(), false, value->defaultArg);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
else if (printWarnings)
|
||||
nullPointerError(tok, tok->str(), value->condition, value->inconclusive);
|
||||
}
|
||||
continue;
|
||||
|
@ -356,7 +358,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
|||
|
||||
if (value->condition == nullptr)
|
||||
nullPointerError(tok, tok->str(), value->inconclusive, value->defaultArg);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
else if (printWarnings)
|
||||
nullPointerError(tok, tok->str(), value->condition, value->inconclusive);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1785,6 +1785,8 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type)
|
|||
//---------------------------------------------------------------------------
|
||||
void CheckOther::checkZeroDivision()
|
||||
{
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
|
||||
MathLib::isInt(tok->strAt(4)) &&
|
||||
|
@ -1804,7 +1806,7 @@ void CheckOther::checkZeroDivision()
|
|||
continue;
|
||||
if (value->condition == nullptr)
|
||||
zerodivError(tok, value->inconclusive);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
else if (printWarnings)
|
||||
zerodivcondError(value->condition,tok,value->inconclusive);
|
||||
}
|
||||
}
|
||||
|
@ -1872,7 +1874,7 @@ void CheckOther::nanInArithmeticExpressionError(const Token *tok)
|
|||
void CheckOther::checkMathFunctions()
|
||||
{
|
||||
bool styleC99 = _settings->isEnabled("style") && _settings->standards.c != Standards::C89 && _settings->standards.cpp != Standards::CPP03;
|
||||
bool printWarnings = _settings->isEnabled("warning");
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
|
@ -2553,8 +2555,8 @@ void CheckOther::checkIncompleteArrayFill()
|
|||
{
|
||||
if (!_settings->inconclusive)
|
||||
return;
|
||||
bool warning = _settings->isEnabled("warning");
|
||||
bool portability = _settings->isEnabled("portability");
|
||||
const bool warning = _settings->isEnabled("warning");
|
||||
const bool portability = _settings->isEnabled("portability");
|
||||
if (!portability && !warning)
|
||||
return;
|
||||
|
||||
|
|
|
@ -1238,6 +1238,7 @@ void CheckStl::checkAutoPointer()
|
|||
std::map<unsigned int, const std::string> mallocVarId; // variables allocated by the malloc-like function
|
||||
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
|
||||
const int malloc = _settings->library.alloc("malloc"); // allocation function, which are not compatible with auto_ptr
|
||||
const bool printStyle = _settings->isEnabled("style");
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, "auto_ptr <")) {
|
||||
|
@ -1284,7 +1285,7 @@ void CheckStl::checkAutoPointer()
|
|||
}
|
||||
} else {
|
||||
if (Token::Match(tok, "%name% = %var% ;")) {
|
||||
if (_settings->isEnabled("style")) {
|
||||
if (printStyle) {
|
||||
std::set<unsigned int>::const_iterator iter = autoPtrVarId.find(tok->tokAt(2)->varId());
|
||||
if (iter != autoPtrVarId.end()) {
|
||||
autoPointerError(tok->tokAt(2));
|
||||
|
|
|
@ -99,6 +99,8 @@ static bool astGetSizeSign(const Settings *settings, const Token *tok, unsigned
|
|||
|
||||
void CheckType::checkTooBigBitwiseShift()
|
||||
{
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
// unknown sizeof(int) => can't run this checker
|
||||
if (_settings->platformType == Settings::Unspecified)
|
||||
return;
|
||||
|
@ -134,7 +136,7 @@ void CheckType::checkTooBigBitwiseShift()
|
|||
const ValueFlow::Value *value = tok->astOperand2()->getValueGE(lhsbits, _settings);
|
||||
if (!value)
|
||||
continue;
|
||||
if (value->condition && !_settings->isEnabled("warning"))
|
||||
if (value->condition && !printWarnings)
|
||||
continue;
|
||||
if (value->inconclusive && !_settings->inconclusive)
|
||||
continue;
|
||||
|
|
|
@ -35,6 +35,8 @@ void CheckVaarg::va_start_argument()
|
|||
{
|
||||
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
const bool printWarnings = _settings->isEnabled("warning");
|
||||
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope* scope = symbolDatabase->functionScopes[i];
|
||||
const Function* function = scope->function;
|
||||
|
@ -48,7 +50,7 @@ void CheckVaarg::va_start_argument()
|
|||
const Variable* var = param2->variable();
|
||||
if (var && var->isReference())
|
||||
referenceAs_va_start_error(param2, var->name());
|
||||
if (var && var->index() + 2 < function->argCount() && _settings->isEnabled("warning")) {
|
||||
if (var && var->index() + 2 < function->argCount() && printWarnings) {
|
||||
std::list<Variable>::const_reverse_iterator it = function->argumentList.rbegin();
|
||||
++it;
|
||||
wrongParameterTo_va_start_error(tok, var->name(), it->name());
|
||||
|
|
|
@ -2870,6 +2870,8 @@ static bool getlines(std::istream &istr, std::string &line)
|
|||
|
||||
bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
|
||||
{
|
||||
const bool printInformation = (_settings && _settings->isEnabled("information"));
|
||||
|
||||
// fill up "macros" with empty configuration macros
|
||||
std::set<std::string> macros;
|
||||
for (std::string::size_type pos = 0; pos < cfg.size();) {
|
||||
|
@ -2917,7 +2919,7 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
|
|||
if (pos2 < code.size() && (std::isalnum((unsigned char)code[pos2]) || code[pos2] == '_'))
|
||||
continue;
|
||||
// macro is used in code, return false
|
||||
if (_settings && _settings->isEnabled("information"))
|
||||
if (printInformation)
|
||||
validateCfgError(cfg, macro);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -7515,6 +7515,7 @@ void Tokenizer::simplifyEnum()
|
|||
std::string className;
|
||||
int classLevel = 0;
|
||||
bool goback = false;
|
||||
const bool printStyle = _settings->isEnabled("style");
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
||||
if (goback) {
|
||||
|
@ -7776,7 +7777,7 @@ void Tokenizer::simplifyEnum()
|
|||
if (prev->str() == "(" && (!Token::Match(prev->tokAt(-2), "%type%|::|*|& %type% (") || prev->strAt(-2) == "else"))
|
||||
continue;
|
||||
shadowVars.insert(arg->str());
|
||||
if (inScope && _settings->isEnabled("style")) {
|
||||
if (inScope && printStyle) {
|
||||
const EnumValue& enumValue = enumValues.find(arg->str())->second;
|
||||
duplicateEnumError(arg, enumValue.name, "Function argument");
|
||||
}
|
||||
|
@ -7796,7 +7797,7 @@ void Tokenizer::simplifyEnum()
|
|||
(Token::Match(prev->previous(), "%type% *|&") && (prev->previous()->isStandardType() || prev->strAt(-1) == "const" || Token::Match(prev->tokAt(-2), ";|{|}")))) {
|
||||
// variable declaration?
|
||||
shadowVars.insert(tok3->str());
|
||||
if (inScope && _settings->isEnabled("style")) {
|
||||
if (inScope && printStyle) {
|
||||
const EnumValue& enumValue = enumValues.find(tok3->str())->second;
|
||||
duplicateEnumError(tok3, enumValue.name, "Variable");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue