Replaced _settings->isEnabled("style") by _settings->isEnabled("warning") wherever warnings are issued

This commit is contained in:
PKEuS 2013-03-03 02:41:59 -08:00
parent ffc82a9d89
commit d78c06dc3f
18 changed files with 106 additions and 78 deletions

View File

@ -119,7 +119,7 @@ void CheckBufferOverrun::possibleReadlinkBufferOverrunError(const Token* tok, co
void CheckBufferOverrun::strncatUsageError(const Token *tok) void CheckBufferOverrun::strncatUsageError(const Token *tok)
{ {
if (_settings && !_settings->isEnabled("style")) if (_settings && !_settings->isEnabled("warning"))
return; return;
reportError(tok, Severity::warning, "strncatUsage", reportError(tok, Severity::warning, "strncatUsage",
@ -147,7 +147,7 @@ void CheckBufferOverrun::pointerOutOfBoundsError(const Token *tok, const std::st
void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok) void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
{ {
if (_settings && !_settings->isEnabled("style")) if (_settings && !_settings->isEnabled("warning"))
return; return;
reportError(tok, Severity::warning, "sizeArgumentAsChar", "The size argument is given as a char constant."); reportError(tok, Severity::warning, "sizeArgumentAsChar", "The size argument is given as a char constant.");
} }
@ -694,7 +694,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
} }
// Check 'float x[10]' arguments in declaration // Check 'float x[10]' arguments in declaration
if (_settings->isEnabled("style")) { if (_settings->isEnabled("warning")) {
const Function* func = tok.function(); const Function* func = tok.function();
// If argument is '%type% a[num]' then check bounds against num // If argument is '%type% a[num]' then check bounds against num
@ -1041,7 +1041,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
(varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str()))) { (varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str()))) {
const std::size_t len = Token::getStrLength(tok->tokAt(varc + 4)); const std::size_t len = Token::getStrLength(tok->tokAt(varc + 4));
if (total_size > 0 && len >= (unsigned int)total_size) { if (total_size > 0 && len >= (unsigned int)total_size) {
bufferOverrunError(tok, varid > 0 ? std::string("") : varnames); bufferOverrunError(tok, varid > 0 ? std::string() : varnames);
continue; continue;
} }
} else if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %var% )", varid)) || } else if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %var% )", varid)) ||
@ -1229,7 +1229,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
unsigned int num = (unsigned int)MathLib::toLongNumber(param3->str()); unsigned int num = (unsigned int)MathLib::toLongNumber(param3->str());
// this is currently 'inconclusive'. See TestBufferOverrun::terminateStrncpy3 // this is currently 'inconclusive'. See TestBufferOverrun::terminateStrncpy3
if (num >= total_size && _settings->isEnabled("style") && _settings->inconclusive) { if (num >= total_size && _settings->isEnabled("warning") && _settings->inconclusive) {
const Token *tok2 = tok->next()->link()->next(); const Token *tok2 = tok->next()->link()->next();
for (; tok2; tok2 = tok2->next()) { for (; tok2; tok2 = tok2->next()) {
if (tok2->varId() == tok->tokAt(2)->varId()) { if (tok2->varId() == tok->tokAt(2)->varId()) {

View File

@ -50,7 +50,9 @@ CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, Err
void CheckClass::constructors() void CheckClass::constructors()
{ {
if (!_settings->isEnabled("style")) bool style = _settings->isEnabled("style");
bool warnings = _settings->isEnabled("warning");
if (!style && !warnings)
return; return;
const std::size_t classes = symbolDatabase->classAndStructScopes.size(); const std::size_t classes = symbolDatabase->classAndStructScopes.size();
@ -62,7 +64,7 @@ void CheckClass::constructors()
continue; continue;
// There are no constructors. // There are no constructors.
if (scope->numConstructors == 0) { if (scope->numConstructors == 0 && style) {
// If there is a private variable, there should be a constructor.. // If there is a private variable, there should be a constructor..
std::list<Variable>::const_iterator var; std::list<Variable>::const_iterator var;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
@ -74,6 +76,9 @@ void CheckClass::constructors()
} }
} }
if (!warnings)
continue;
// #3196 => bailout if there are nested unions // #3196 => bailout if there are nested unions
// TODO: handle union variables better // TODO: handle union variables better
{ {
@ -1071,7 +1076,7 @@ void CheckClass::operatorEqRetRefThisError(const Token *tok)
void CheckClass::operatorEqToSelf() void CheckClass::operatorEqToSelf()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const std::size_t classes = symbolDatabase->classAndStructScopes.size(); const std::size_t classes = symbolDatabase->classAndStructScopes.size();
@ -1311,7 +1316,7 @@ void CheckClass::virtualDestructorError(const Token *tok, const std::string &Bas
void CheckClass::thisSubtraction() void CheckClass::thisSubtraction()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const Token *tok = _tokenizer->tokens(); const Token *tok = _tokenizer->tokens();

View File

@ -66,7 +66,7 @@ void CheckExceptionSafety::destructors()
void CheckExceptionSafety::deallocThrow() void CheckExceptionSafety::deallocThrow()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();

View File

@ -307,7 +307,7 @@ void CheckIO::useClosedFileError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckIO::invalidScanf() void CheckIO::invalidScanf()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning") && !_settings->isEnabled("portability"))
return; return;
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -343,7 +343,7 @@ void CheckIO::invalidScanf()
} }
else if (std::isalpha(formatstr[i]) || formatstr[i] == '[') { else if (std::isalpha(formatstr[i]) || formatstr[i] == '[') {
if (formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) // #3490 - field width limits are only necessary for string input if ((formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) && _settings->isEnabled("warning")) // #3490 - field width limits are only necessary for string input
invalidScanfError(tok, false); invalidScanfError(tok, false);
else if (formatstr[i] != 'n' && formatstr[i] != 'c' && _settings->platformType != Settings::Win32A && _settings->platformType != Settings::Win32W && _settings->platformType != Settings::Win64 && _settings->isEnabled("portability")) else if (formatstr[i] != 'n' && formatstr[i] != 'c' && _settings->platformType != Settings::Win32A && _settings->platformType != Settings::Win32W && _settings->platformType != Settings::Win64 && _settings->isEnabled("portability"))
invalidScanfError(tok, true); // Warn about libc bug in versions prior to 2.13-25 invalidScanfError(tok, true); // Warn about libc bug in versions prior to 2.13-25
@ -425,7 +425,7 @@ static bool isKnownType(const Variable* var, const Token* varTypeTok)
void CheckIO::checkWrongPrintfScanfArguments() void CheckIO::checkWrongPrintfScanfArguments()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
bool warning = _settings->isEnabled("style"); bool warning = _settings->isEnabled("warning");
std::size_t functions = symbolDatabase->functionScopes.size(); std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t j = 0; j < functions; ++j) { for (std::size_t j = 0; j < functions; ++j) {

View File

@ -100,7 +100,7 @@ void CheckLeakAutoVar::deallocReturnError(const Token *tok, const std::string &v
void CheckLeakAutoVar::configurationInfo(const Token* tok, const std::string &functionName) void CheckLeakAutoVar::configurationInfo(const Token* tok, const std::string &functionName)
{ {
if (((!cfgalloc.empty() || !cfgdealloc.empty()) && _settings->isEnabled("style")) || _settings->experimental) { if (((!cfgalloc.empty() || !cfgdealloc.empty()) && _settings->isEnabled("information")) || _settings->experimental) {
reportError(tok, reportError(tok,
Severity::information, Severity::information,
"leakconfiguration", "leakconfiguration",

View File

@ -2495,7 +2495,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke
// Check that public functions deallocate the pointers that they allocate. // Check that public functions deallocate the pointers that they allocate.
// There is no checking how these functions are used and therefore it // There is no checking how these functions are used and therefore it
// isn't established if there is real leaks or not. // isn't established if there is real leaks or not.
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const unsigned int varid = classtok->varId(); const unsigned int varid = classtok->varId();

View File

@ -320,7 +320,7 @@ void CheckOther::clarifyConditionError(const Token *tok, bool assign, bool boolo
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::clarifyStatement() void CheckOther::clarifyStatement()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -407,7 +407,7 @@ void CheckOther::bitwiseOnBooleanError(const Token *tok, const std::string &varn
void CheckOther::checkSuspiciousSemicolon() void CheckOther::checkSuspiciousSemicolon()
{ {
if (!_settings->inconclusive || !_settings->isEnabled("style")) if (!_settings->inconclusive || !_settings->isEnabled("warning"))
return; return;
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -486,7 +486,7 @@ static std::string analyzeType(const Token* tok)
void CheckOther::invalidPointerCast() void CheckOther::invalidPointerCast()
{ {
if (!_settings->isEnabled("style") && !_settings->isEnabled("portability")) if (!_settings->isEnabled("warning") && !_settings->isEnabled("portability"))
return; return;
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -568,7 +568,7 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkSizeofForNumericParameter() void CheckOther::checkSizeofForNumericParameter()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -604,8 +604,7 @@ void CheckOther::sizeofForNumericParameterError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkPipeParameterSize() void CheckOther::checkPipeParameterSize()
{ {
if (!_settings->isEnabled("warning") if (!_settings->standards.posix)
|| !_settings->standards.posix)
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -682,7 +681,7 @@ void CheckOther::sizeofForArrayParameterError(const Token *tok)
void CheckOther::checkSizeofForPointerSize() void CheckOther::checkSizeofForPointerSize()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -796,7 +795,9 @@ static void eraseNotLocalArg(std::map<unsigned int, const Token*>& container, co
void CheckOther::checkRedundantAssignment() void CheckOther::checkRedundantAssignment()
{ {
if (!_settings->isEnabled("performance")) bool performance = _settings->isEnabled("performance");
bool warning = _settings->isEnabled("warning");
if (!warning && !performance)
return; return;
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
@ -840,9 +841,9 @@ void CheckOther::checkRedundantAssignment()
} }
} }
if (error) { if (error) {
if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok)) if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok) && warning)
redundantAssignmentInSwitchError(it->second, tok, tok->str()); redundantAssignmentInSwitchError(it->second, tok, tok->str());
else else if (performance)
redundantAssignmentError(it->second, tok, tok->str(), nonLocal(it->second->variable())); // Inconclusive for non-local variables redundantAssignmentError(it->second, tok, tok->str(), nonLocal(it->second->variable())); // Inconclusive for non-local variables
} }
it->second = tok; it->second = tok;
@ -871,9 +872,9 @@ void CheckOther::checkRedundantAssignment()
if (it == memAssignments.end()) if (it == memAssignments.end())
memAssignments[param1->varId()] = tok; memAssignments[param1->varId()] = tok;
else { else {
if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok)) if (scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok) && warning)
redundantCopyInSwitchError(it->second, tok, param1->str()); redundantCopyInSwitchError(it->second, tok, param1->str());
else else if (performance)
redundantCopyError(it->second, tok, param1->str()); redundantCopyError(it->second, tok, param1->str());
} }
} }
@ -963,7 +964,7 @@ static inline bool isFunctionOrBreakPattern(const Token *tok)
void CheckOther::checkRedundantAssignmentInSwitch() void CheckOther::checkRedundantAssignmentInSwitch()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -1196,7 +1197,7 @@ void CheckOther::switchCaseFallThrough(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkSuspiciousCaseInSwitch() void CheckOther::checkSuspiciousCaseInSwitch()
{ {
if (!_settings->inconclusive || !_settings->isEnabled("style")) if (!_settings->inconclusive || !_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -1241,7 +1242,7 @@ void CheckOther::suspiciousCaseInSwitchError(const Token* tok, const std::string
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkSuspiciousEqualityComparison() void CheckOther::checkSuspiciousEqualityComparison()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
@ -1274,9 +1275,7 @@ void CheckOther::checkSuspiciousEqualityComparison()
// Skip over for() loop conditions because "for (;running==1;)" // Skip over for() loop conditions because "for (;running==1;)"
// is a bit strange, but not necessarily incorrect. // is a bit strange, but not necessarily incorrect.
tok = closeParen; tok = closeParen;
} } else if (Token::Match(tok, "[;{}] *| %var% == %any% ;")) {
if (Token::Match(tok, "[;{}] *| %var% == %any% ;")) {
// Exclude compound statements surrounded by parentheses, such as // Exclude compound statements surrounded by parentheses, such as
// printf("%i\n", ({x==0;})); // printf("%i\n", ({x==0;}));
@ -1314,7 +1313,7 @@ static inline const Token *findSelfAssignPattern(const Token *start)
void CheckOther::checkSelfAssignment() void CheckOther::checkSelfAssignment()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const Token *tok = findSelfAssignPattern(_tokenizer->tokens()); const Token *tok = findSelfAssignPattern(_tokenizer->tokens());
@ -1364,7 +1363,7 @@ static inline const Token *findAssertPattern(const Token *start)
void CheckOther::checkAssignmentInAssert() void CheckOther::checkAssignmentInAssert()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const Token *tok = findAssertPattern(_tokenizer->tokens()); const Token *tok = findAssertPattern(_tokenizer->tokens());
@ -1457,7 +1456,9 @@ static bool analyzeLogicOperatorCondition(const Condition& c1, const Condition&
void CheckOther::checkIncorrectLogicOperator() void CheckOther::checkIncorrectLogicOperator()
{ {
if (!_settings->isEnabled("style")) bool style = _settings->isEnabled("style");
bool warning = _settings->isEnabled("warning");
if (!style && !warning)
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -1646,12 +1647,16 @@ void CheckOther::checkIncorrectLogicOperator()
if (error) { if (error) {
if (conditions[i].error == AlwaysFalse || conditions[i].error == AlwaysTrue) { if (conditions[i].error == AlwaysFalse || conditions[i].error == AlwaysTrue) {
const std::string text = cond1str + " " + op2Tok->str() + " " + cond2str; if (warning) {
incorrectLogicOperatorError(term1Tok, text, conditions[i].error == AlwaysTrue); const std::string text = cond1str + " " + op2Tok->str() + " " + cond2str;
incorrectLogicOperatorError(term1Tok, text, conditions[i].error == AlwaysTrue);
}
} else { } else {
const std::string text = "If " + cond1str + ", the comparison " + cond2str + if (style) {
" is always " + ((conditions[i].error == SecondTrue || conditions[i].error == AlwaysTrue) ? "true" : "false") + "."; const std::string text = "If " + cond1str + ", the comparison " + cond2str +
redundantConditionError(term1Tok, text); " is always " + ((conditions[i].error == SecondTrue || conditions[i].error == AlwaysTrue) ? "true" : "false") + ".";
redundantConditionError(term1Tok, text);
}
} }
break; break;
} }
@ -1772,7 +1777,7 @@ static bool isNonBoolStdType(const Variable* var)
} }
void CheckOther::checkComparisonOfBoolWithInt() void CheckOther::checkComparisonOfBoolWithInt()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -1947,7 +1952,7 @@ bool CheckOther::isSigned(const Variable* var) const
void CheckOther::checkUnsignedDivision() void CheckOther::checkUnsignedDivision()
{ {
bool style = _settings->isEnabled("style"); bool warning = _settings->isEnabled("warning");
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size(); const std::size_t functions = symbolDatabase->functionScopes.size();
@ -1968,7 +1973,7 @@ void CheckOther::checkUnsignedDivision()
if (tok->strAt(1)[0] == '-' && isUnsigned(tok->tokAt(3)->variable())) { if (tok->strAt(1)[0] == '-' && isUnsigned(tok->tokAt(3)->variable())) {
udivError(tok->next(), false); udivError(tok->next(), false);
} }
} else if (Token::Match(tok->next(), "%var% / %var%") && _settings->inconclusive && style && !ifTok) { } else if (Token::Match(tok->next(), "%var% / %var%") && _settings->inconclusive && warning && !ifTok) {
const Variable* var1 = tok->next()->variable(); const Variable* var1 = tok->next()->variable();
const Variable* var2 = tok->tokAt(3)->variable(); const Variable* var2 = tok->tokAt(3)->variable();
if ((isUnsigned(var1) && isSigned(var2)) || (isUnsigned(var2) && isSigned(var1))) { if ((isUnsigned(var1) && isSigned(var2)) || (isUnsigned(var2) && isSigned(var1))) {
@ -1995,7 +2000,7 @@ void CheckOther::udivError(const Token *tok, bool inconclusive)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkMemsetZeroBytes() void CheckOther::checkMemsetZeroBytes()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -2227,7 +2232,7 @@ static bool isSignedChar(const Variable* var)
void CheckOther::checkCharVariable() void CheckOther::checkCharVariable()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -2310,7 +2315,7 @@ void CheckOther::charBitOpError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkIncompleteStatement() void CheckOther::checkIncompleteStatement()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
@ -2661,7 +2666,7 @@ void CheckOther::comparisonOfBoolWithBoolError(const Token *tok, const std::stri
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkIncorrectStringCompare() void CheckOther::checkIncorrectStringCompare()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -3364,7 +3369,7 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkAlwaysTrueOrFalseStringCompare() void CheckOther::checkAlwaysTrueOrFalseStringCompare()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const Token *tok = _tokenizer->tokens(); const Token *tok = _tokenizer->tokens();
@ -3426,7 +3431,7 @@ void CheckOther::alwaysTrueStringVariableCompareError(const Token *tok, const st
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::checkSuspiciousStringCompare() void CheckOther::checkSuspiciousStringCompare()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
@ -3469,6 +3474,9 @@ void CheckOther::suspiciousStringCompareError(const Token* tok, const std::strin
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::checkModuloAlwaysTrueFalse() void CheckOther::checkModuloAlwaysTrueFalse()
{ {
if (!_settings->isEnabled("warning"))
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size(); const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {
@ -3493,8 +3501,9 @@ void CheckOther::moduloAlwaysTrueFalseError(const Token* tok, const std::string&
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::sizeofsizeof() void CheckOther::sizeofsizeof()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "sizeof (| sizeof")) { if (Token::Match(tok, "sizeof (| sizeof")) {
sizeofsizeofError(tok); sizeofsizeofError(tok);
@ -3516,7 +3525,7 @@ void CheckOther::sizeofsizeofError(const Token *tok)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::sizeofCalculation() void CheckOther::sizeofCalculation()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
@ -3575,7 +3584,7 @@ void CheckOther::redundantGetAndSetUserIdError(const Token *tok)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::suspiciousSizeofCalculation() void CheckOther::suspiciousSizeofCalculation()
{ {
if (!_settings->isEnabled("style") || !_settings->inconclusive) if (!_settings->isEnabled("warning") || !_settings->inconclusive)
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
@ -3635,7 +3644,7 @@ void CheckOther::assignBoolToPointerError(const Token *tok)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CheckOther::checkComparisonOfBoolExpressionWithInt() void CheckOther::checkComparisonOfBoolExpressionWithInt()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("warning"))
return; return;
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
@ -3879,7 +3888,9 @@ void CheckOther::negativeBitwiseShiftError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkIncompleteArrayFill() void CheckOther::checkIncompleteArrayFill()
{ {
if (!_settings->inconclusive || !_settings->isEnabled("style")) bool warning = _settings->isEnabled("warning");
bool portability = _settings->isEnabled("portability");
if (!_settings->inconclusive || (!portability && !warning))
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -3895,9 +3906,10 @@ void CheckOther::checkIncompleteArrayFill()
if (MathLib::toLongNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) { if (MathLib::toLongNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
unsigned int size = _tokenizer->sizeOfType(var->typeStartToken()); unsigned int size = _tokenizer->sizeOfType(var->typeStartToken());
if ((size != 1 && size != 100 && size != 0) || var->typeEndToken()->str() == "*") if ((size != 1 && size != 100 && size != 0) || var->typeEndToken()->str() == "*") {
incompleteArrayFillError(tok, var->name(), tok->str(), false); if (warning)
else if (var->typeStartToken()->str() == "bool" && _settings->isEnabled("portability")) // sizeof(bool) is not 1 on all platforms incompleteArrayFillError(tok, var->name(), tok->str(), false);
} else if (var->typeStartToken()->str() == "bool" && portability) // sizeof(bool) is not 1 on all platforms
incompleteArrayFillError(tok, var->name(), tok->str(), true); incompleteArrayFillError(tok, var->name(), tok->str(), true);
} }
} }
@ -3921,7 +3933,7 @@ void CheckOther::incompleteArrayFillError(const Token* tok, const std::string& b
void CheckOther::oppositeInnerCondition() void CheckOther::oppositeInnerCondition()
{ {
// FIXME: This check is experimental because of #4170 and #4186. Fix those tickets and remove the "experimental". // FIXME: This check is experimental because of #4170 and #4186. Fix those tickets and remove the "experimental".
if (!_settings->isEnabled("style") || !_settings->inconclusive || !_settings->experimental) if (!_settings->isEnabled("warning") || !_settings->inconclusive || !_settings->experimental)
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

View File

@ -774,7 +774,9 @@ static bool if_findCompare(const Token * const tokBack, bool str)
void CheckStl::if_find() void CheckStl::if_find()
{ {
if (!_settings->isEnabled("style")) bool warning = _settings->isEnabled("warning");
bool performance = _settings->isEnabled("performance");
if (!warning && !performance)
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -811,9 +813,9 @@ void CheckStl::if_find()
continue; continue;
// stl container // stl container
if (Token::Match(decl, "std :: %var% < %type% > &| %varid%", varid)) if (Token::Match(decl, "std :: %var% < %type% > &| %varid%", varid) && warning)
if_findError(tok, false); if_findError(tok, false);
else if (str) else if (str && performance)
if_findError(tok, true); if_findError(tok, true);
} }
} }
@ -849,24 +851,24 @@ void CheckStl::if_find()
if (Token::Match(decl, "%var% <")) { if (Token::Match(decl, "%var% <")) {
decl = decl->tokAt(2); decl = decl->tokAt(2);
//stl-like //stl-like
if (Token::Match(decl, "std :: %var% < %type% > > &| %varid%", varid)) if (Token::Match(decl, "std :: %var% < %type% > > &| %varid%", varid) && warning)
if_findError(tok, false); if_findError(tok, false);
//not stl-like, then let's hope it's a pointer or an array //not stl-like, then let's hope it's a pointer or an array
else if (Token::Match(decl, "%type% >")) { else if (Token::Match(decl, "%type% >")) {
decl = decl->tokAt(2); decl = decl->tokAt(2);
if (Token::Match(decl, "* &| %varid%", varid) || if ((Token::Match(decl, "* &| %varid%", varid) ||
Token::Match(decl, "&| %varid% [ ]| %any% ]| ", varid)) Token::Match(decl, "&| %varid% [ ]| %any% ]| ", varid)) && warning)
if_findError(tok, false); if_findError(tok, false);
} }
else if (Token::Match(decl, "std :: string|wstring > &| %varid%", varid)) else if (Token::Match(decl, "std :: string|wstring > &| %varid%", varid) && performance)
if_findError(tok, true); if_findError(tok, true);
} }
else if (decl && decl->str() == "string") { else if (decl && decl->str() == "string") {
decl = decl->next(); decl = decl->next();
if (Token::Match(decl, "* &| %varid%", varid) || if (Token::Match(decl, "* &| %varid%", varid) ||
Token::Match(decl, "&| %varid% [ ]| %any% ]| ", varid)) Token::Match(decl, "&| %varid% [ ]| %any% ]| ", varid) && performance)
if_findError(tok, true); if_findError(tok, true);
} }
} }
@ -874,7 +876,7 @@ void CheckStl::if_find()
else if (Token::Match(tok, "std :: find|find_if (")) { else if (Token::Match(tok, "std :: find|find_if (")) {
// check that result is checked properly // check that result is checked properly
if (!if_findCompare(tok->linkAt(3), false)) { if (!if_findCompare(tok->linkAt(3), false) && warning) {
if_findError(tok, false); if_findError(tok, false);
} }
} }
@ -1017,6 +1019,9 @@ void CheckStl::redundantIfRemoveError(const Token *tok)
void CheckStl::missingComparison() void CheckStl::missingComparison()
{ {
if (!_settings->isEnabled("warning"))
return;
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
@ -1363,8 +1368,8 @@ void CheckStl::autoPointerArrayError(const Token *tok)
void CheckStl::uselessCalls() void CheckStl::uselessCalls()
{ {
bool performance = _settings->isEnabled("performance"); bool performance = _settings->isEnabled("performance");
bool style = _settings->isEnabled("style"); bool warning = _settings->isEnabled("warning");
if (!performance && !style) if (!performance && !warning)
return; return;
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
@ -1373,7 +1378,7 @@ void CheckStl::uselessCalls()
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (tok->varId() && Token::Match(tok, "%var% . compare|find|rfind|find_first_not_of|find_first_of|find_last_not_of|find_last_of ( %var% [,)]") && if (tok->varId() && Token::Match(tok, "%var% . compare|find|rfind|find_first_not_of|find_first_of|find_last_not_of|find_last_of ( %var% [,)]") &&
tok->varId() == tok->tokAt(4)->varId() && style) { tok->varId() == tok->tokAt(4)->varId() && warning) {
uselessCallsReturnValueError(tok->tokAt(4), tok->str(), tok->strAt(2)); uselessCallsReturnValueError(tok->tokAt(4), tok->str(), tok->strAt(2));
} else if (tok->varId() && Token::Match(tok, "%var% . swap ( %var% )") && } else if (tok->varId() && Token::Match(tok, "%var% . swap ( %var% )") &&
tok->varId() == tok->tokAt(4)->varId() && performance) { tok->varId() == tok->tokAt(4)->varId() && performance) {
@ -1386,7 +1391,7 @@ void CheckStl::uselessCalls()
uselessCallsSubstrError(tok, false); uselessCallsSubstrError(tok, false);
} else if (Token::simpleMatch(tok->linkAt(2)->tokAt(-2), ", 0 )")) } else if (Token::simpleMatch(tok->linkAt(2)->tokAt(-2), ", 0 )"))
uselessCallsSubstrError(tok, true); uselessCallsSubstrError(tok, true);
} else if (Token::Match(tok, "[{};] %var% . empty ( ) ;") && style) } else if (Token::Match(tok, "[{};] %var% . empty ( ) ;") && warning)
uselessCallsEmptyError(tok->next()); uselessCallsEmptyError(tok->next());
else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument()) else if (Token::Match(tok, "[{};] std :: remove|remove_if|unique (") && tok->tokAt(5)->nextArgument())
uselessCallsRemoveError(tok->next(), tok->strAt(3)); uselessCallsRemoveError(tok->next(), tok->strAt(3));

View File

@ -41,6 +41,7 @@ private:
settings.inconclusive = true; settings.inconclusive = true;
settings.standards.posix = true; settings.standards.posix = true;
settings.experimental = experimental; settings.experimental = experimental;
settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("portability"); settings.addEnabled("portability");

View File

@ -50,7 +50,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -768,7 +768,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
@ -2369,7 +2369,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -40,6 +40,7 @@ private:
Settings settings; Settings settings;
settings.inconclusive = showAll; settings.inconclusive = showAll;
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -40,7 +40,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
settings.inconclusive = inconclusive; settings.inconclusive = inconclusive;
// Tokenize.. // Tokenize..

View File

@ -40,7 +40,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -53,6 +53,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
if (portability) if (portability)
settings.addEnabled("portability"); settings.addEnabled("portability");

View File

@ -3898,6 +3898,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
// Tokenize.. // Tokenize..

View File

@ -253,6 +253,7 @@ private:
filename = "test.cpp"; filename = "test.cpp";
Settings settings; Settings settings;
settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance"); settings.addEnabled("performance");
settings.experimental = true; settings.experimental = true;
@ -944,7 +945,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("warning");
if (portability) if (portability)
settings.addEnabled("portability"); settings.addEnabled("portability");
settings.inconclusive = inconclusive; settings.inconclusive = inconclusive;

View File

@ -130,6 +130,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("warning");
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance"); settings.addEnabled("performance");
settings.inconclusive = inconclusive; settings.inconclusive = inconclusive;