Refactoring: Disable inconclusive checks. They can still be activated for debugging/testing purposes
This commit is contained in:
parent
7763d25847
commit
e9b4ea44a2
|
@ -64,7 +64,7 @@ void CheckBufferOverrun::arrayIndexOutOfBounds(int size, int index)
|
|||
if (size <= 1 || _callStack.size() > 1)
|
||||
{
|
||||
severity = Severity::possibleError;
|
||||
if (_settings->_showAll == false)
|
||||
if (_settings->inconclusive == false)
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -88,7 +88,7 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok, const std::string &varn
|
|||
if (_callStack.size() > 0)
|
||||
{
|
||||
severity = Severity::possibleError;
|
||||
if (_settings->_showAll == false)
|
||||
if (_settings->inconclusive == false)
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -109,7 +109,7 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok, const std::string &varn
|
|||
|
||||
void CheckBufferOverrun::dangerousStdCin(const Token *tok)
|
||||
{
|
||||
if (_settings && _settings->_showAll == false)
|
||||
if (_settings && _settings->inconclusive == false)
|
||||
return;
|
||||
|
||||
reportError(tok, Severity::possibleError, "dangerousStdCin", "Dangerous usage of std::cin, possible buffer overrun");
|
||||
|
@ -117,7 +117,7 @@ void CheckBufferOverrun::dangerousStdCin(const Token *tok)
|
|||
|
||||
void CheckBufferOverrun::strncatUsage(const Token *tok)
|
||||
{
|
||||
if (_settings && _settings->_showAll == false)
|
||||
if (_settings && _settings->inconclusive == false)
|
||||
return;
|
||||
|
||||
reportError(tok, Severity::possibleError, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
|
||||
|
@ -130,7 +130,7 @@ void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what)
|
|||
|
||||
void CheckBufferOverrun::sizeArgumentAsChar(const Token *tok)
|
||||
{
|
||||
if (_settings && _settings->_showAll == false)
|
||||
if (_settings && _settings->inconclusive == false)
|
||||
return;
|
||||
|
||||
reportError(tok, Severity::possibleError, "sizeArgumentAsChar", "The size argument is given as a char constant");
|
||||
|
@ -700,7 +700,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
if (Token::Match(tok, "%var% ("))
|
||||
{
|
||||
// Only perform this checking if showAll setting is enabled..
|
||||
if (!_settings->_showAll)
|
||||
if (!_settings->inconclusive)
|
||||
continue;
|
||||
|
||||
unsigned int parlevel = 0, par = 0;
|
||||
|
|
|
@ -481,7 +481,7 @@ void CheckClass::constructors()
|
|||
}
|
||||
}
|
||||
|
||||
if (hasPrivateConstructor && !_settings->_showAll)
|
||||
if (hasPrivateConstructor && !_settings->inconclusive)
|
||||
{
|
||||
/** @todo Handle private constructors. Right now to avoid
|
||||
* false positives we just bail out */
|
||||
|
@ -542,7 +542,7 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
|
|||
const std::string className = tok1->strAt(1);
|
||||
|
||||
// Check that all member variables are initialized..
|
||||
bool withClasses = bool(_settings->_showAll && funcname == "operator =");
|
||||
bool withClasses = bool(_settings->inconclusive && funcname == "operator =");
|
||||
Var *varlist = getVarList(tok1, withClasses, isStruct);
|
||||
|
||||
int indentlevel = 0;
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
checkClass.operatorEq();
|
||||
checkClass.privateFunctions();
|
||||
checkClass.operatorEqRetRefThis();
|
||||
if (settings->_showAll)
|
||||
if (settings->inconclusive)
|
||||
{
|
||||
checkClass.thisSubtraction();
|
||||
checkClass.operatorEqToSelf();
|
||||
|
|
|
@ -603,7 +603,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
--parlevel;
|
||||
if (parlevel < 1)
|
||||
{
|
||||
return (_settings && _settings->_showAll) ? 0 : "callfunc";
|
||||
return (_settings && _settings->inconclusive) ? 0 : "callfunc";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -800,7 +800,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
{
|
||||
if (isclass(_tokenizer, tok->tokAt(3)))
|
||||
{
|
||||
if (_settings->_showAll)
|
||||
if (_settings->inconclusive)
|
||||
{
|
||||
|
||||
if (_settings->isAutoDealloc(tok->strAt(3)))
|
||||
|
@ -1380,7 +1380,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
}
|
||||
|
||||
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
|
||||
else if (!_settings->_showAll && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
||||
else if (!_settings->inconclusive && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
||||
{
|
||||
Token::eraseTokens(tok2, tok2->tokAt(4));
|
||||
done = false;
|
||||
|
@ -1399,7 +1399,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
// Otherwise, only the "if" will be deleted
|
||||
else if (Token::Match(tok2, "[;{}] if assign|dealloc|use ; !!else"))
|
||||
{
|
||||
if (_settings->_showAll && tok2->tokAt(2)->str() != "assign" && !Token::simpleMatch(tok2->tokAt(2), "dealloc ; dealloc"))
|
||||
if (_settings->inconclusive && tok2->tokAt(2)->str() != "assign" && !Token::simpleMatch(tok2->tokAt(2), "dealloc ; dealloc"))
|
||||
{
|
||||
Token::eraseTokens(tok2, tok2->tokAt(3));
|
||||
all = true;
|
||||
|
@ -1471,7 +1471,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
}
|
||||
|
||||
// Reducing if..
|
||||
else if (_settings->_showAll)
|
||||
else if (_settings->inconclusive)
|
||||
{
|
||||
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
|
||||
{
|
||||
|
@ -1616,7 +1616,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
}
|
||||
|
||||
// Remove the "if break|continue ;" that follows "dealloc ; alloc ;"
|
||||
if (! _settings->_showAll && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;"))
|
||||
if (! _settings->inconclusive && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;"))
|
||||
{
|
||||
tok2 = tok2->tokAt(3);
|
||||
Token::eraseTokens(tok2, tok2->tokAt(3));
|
||||
|
@ -1881,7 +1881,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
}
|
||||
|
||||
// If "--all" is given, remove all "callfunc"..
|
||||
if (done && _settings->_showAll)
|
||||
if (done && _settings->inconclusive)
|
||||
{
|
||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
|
@ -2047,7 +2047,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
return;
|
||||
}
|
||||
|
||||
if ((result = findleak(tok, _settings->_showAll)) != NULL)
|
||||
if ((result = findleak(tok, _settings->inconclusive)) != NULL)
|
||||
{
|
||||
memoryLeak(result, varname, alloctype, all);
|
||||
}
|
||||
|
@ -2293,7 +2293,7 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
|
|||
if (_settings->isAutoDealloc(tok->str().c_str()))
|
||||
continue;
|
||||
|
||||
if (_settings->_showAll || !isclass(_tokenizer, tok))
|
||||
if (_settings->inconclusive || !isclass(_tokenizer, tok))
|
||||
variable(classname.back(), tok->tokAt(2));
|
||||
}
|
||||
}
|
||||
|
@ -2301,7 +2301,7 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
|
|||
|
||||
void CheckMemoryLeakInClass::variable(const std::string &classname, const Token *tokVarname)
|
||||
{
|
||||
if (!_settings->_showAll)
|
||||
if (!_settings->inconclusive)
|
||||
return;
|
||||
|
||||
const std::string varname = tokVarname->strAt(0);
|
||||
|
|
|
@ -307,7 +307,7 @@ void CheckOther::invalidFunctionUsage()
|
|||
|
||||
void CheckOther::checkUnsignedDivision()
|
||||
{
|
||||
if (!_settings->_showAll || !_settings->_checkCodingStyle)
|
||||
if (!_settings->inconclusive || !_settings->_checkCodingStyle)
|
||||
return;
|
||||
|
||||
// Check for "ivar / uvar" and "uvar / ivar"
|
||||
|
@ -327,16 +327,13 @@ void CheckOther::checkUnsignedDivision()
|
|||
tok->tokAt(1)->varId() != 0 &&
|
||||
tok->tokAt(3)->varId() != 0)
|
||||
{
|
||||
if (ErrorLogger::udivWarning(*_settings))
|
||||
{
|
||||
char sign1 = varsign[tok->tokAt(1)->varId()];
|
||||
char sign2 = varsign[tok->tokAt(3)->varId()];
|
||||
char sign1 = varsign[tok->tokAt(1)->varId()];
|
||||
char sign2 = varsign[tok->tokAt(3)->varId()];
|
||||
|
||||
if (sign1 && sign2 && sign1 != sign2)
|
||||
{
|
||||
// One of the operands are signed, the other is unsigned..
|
||||
udivWarning(tok->next());
|
||||
}
|
||||
if (sign1 && sign2 && sign1 != sign2)
|
||||
{
|
||||
// One of the operands are signed, the other is unsigned..
|
||||
udivWarning(tok->next());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2499,7 +2496,7 @@ void CheckOther::executionPaths()
|
|||
{
|
||||
// no writing if multiple threads are used (TODO: thread safe analysis?)
|
||||
if (_settings->_jobs == 1)
|
||||
CheckUninitVar::analyseFunctions(_tokenizer->tokens(), CheckUninitVar::uvarFunctions, _settings->_showAll);
|
||||
CheckUninitVar::analyseFunctions(_tokenizer->tokens(), CheckUninitVar::uvarFunctions, _settings->inconclusive);
|
||||
|
||||
CheckUninitVar c(this);
|
||||
checkExecutionPaths(_tokenizer->tokens(), &c);
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
checkOther.checkConstantFunctionParameter();
|
||||
checkOther.checkIncompleteStatement();
|
||||
checkOther.unreachableCode();
|
||||
if (settings->_showAll)
|
||||
if (settings->inconclusive)
|
||||
{
|
||||
checkOther.postIncrement();
|
||||
}
|
||||
|
|
|
@ -55,10 +55,9 @@ public:
|
|||
checkStl.stlBoundries();
|
||||
checkStl.if_find();
|
||||
|
||||
if (settings->_checkCodingStyle)
|
||||
if (settings->_checkCodingStyle && settings->inconclusive)
|
||||
{
|
||||
if (settings->_showAll)
|
||||
checkStl.size();
|
||||
checkStl.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -117,23 +117,6 @@ public:
|
|||
*/
|
||||
virtual void reportStatus(unsigned int index, unsigned int max) = 0;
|
||||
|
||||
|
||||
static bool arrayIndexOutOfBounds(const Settings &s)
|
||||
{
|
||||
return s._showAll;
|
||||
}
|
||||
|
||||
static bool bufferOverrun(const Settings &s)
|
||||
{
|
||||
return s._showAll;
|
||||
}
|
||||
|
||||
|
||||
static bool strncatUsage(const Settings &s)
|
||||
{
|
||||
return s._showAll;
|
||||
}
|
||||
|
||||
static bool outOfBounds()
|
||||
{
|
||||
return true;
|
||||
|
@ -189,11 +172,6 @@ public:
|
|||
reportErr(ErrorLogger::ErrorMessage(loc, "style", "The function '" + funcname + "' is never used", "unusedFunction"));
|
||||
}
|
||||
|
||||
static bool unusedFunction(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle || s._showAll;
|
||||
}
|
||||
|
||||
|
||||
static bool mismatchAllocDealloc()
|
||||
{
|
||||
|
@ -205,12 +183,6 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool memleakall(const Settings &s)
|
||||
{
|
||||
return s._showAll;
|
||||
}
|
||||
|
||||
|
||||
static bool resourceLeak()
|
||||
{
|
||||
return true;
|
||||
|
@ -270,12 +242,6 @@ public:
|
|||
}
|
||||
|
||||
|
||||
static bool udivWarning(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle || s._showAll;
|
||||
}
|
||||
|
||||
|
||||
static bool unusedStructMember(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle;
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#include <stdexcept>
|
||||
|
||||
Settings::Settings()
|
||||
: inconclusive(false)
|
||||
{
|
||||
_debug = false;
|
||||
_showAll = false;
|
||||
_checkCodingStyle = false;
|
||||
_errorsOnly = false;
|
||||
_inlineSuppressions = false;
|
||||
|
@ -40,6 +40,40 @@ Settings::Settings()
|
|||
_terminate = false;
|
||||
}
|
||||
|
||||
Settings::Settings(const Settings &s)
|
||||
: inconclusive(s.inconclusive)
|
||||
{
|
||||
*this = s;
|
||||
}
|
||||
|
||||
// Constructor used in unit testing..
|
||||
Settings::Settings(bool all)
|
||||
: inconclusive(all)
|
||||
{
|
||||
Settings s;
|
||||
*this = s; // This assigns all members except "inconclusive"
|
||||
}
|
||||
|
||||
const Settings &Settings::operator=(const Settings & s)
|
||||
{
|
||||
if (&s == this)
|
||||
return *this;
|
||||
|
||||
_debug = s._debug;
|
||||
_checkCodingStyle = s._checkCodingStyle;
|
||||
_errorsOnly = s._errorsOnly;
|
||||
_inlineSuppressions = s._inlineSuppressions;
|
||||
_verbose = s._verbose;
|
||||
_force = s._force;
|
||||
_xml = s._xml;
|
||||
_jobs = s._jobs;
|
||||
_exitCode = s._exitCode;
|
||||
_showtime = s._showtime;
|
||||
_append = s._append;
|
||||
_terminate = s._terminate;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
|
||||
|
@ -140,11 +174,9 @@ void Settings::addEnabled(const std::string &str)
|
|||
bool handled = false;
|
||||
|
||||
if (str == "all")
|
||||
handled = _checkCodingStyle = _showAll = true;
|
||||
handled = _checkCodingStyle = true;
|
||||
else if (str == "style")
|
||||
handled = _checkCodingStyle = true;
|
||||
else if (str == "possibleError")
|
||||
handled = _showAll = true;
|
||||
|
||||
std::set<std::string> id;
|
||||
id.insert("exceptNew");
|
||||
|
|
|
@ -48,15 +48,26 @@ private:
|
|||
|
||||
/** @brief terminate checking */
|
||||
bool _terminate;
|
||||
|
||||
Settings(bool all);
|
||||
|
||||
public:
|
||||
Settings();
|
||||
Settings(const Settings &s);
|
||||
const Settings &operator=(const Settings &s);
|
||||
virtual ~Settings();
|
||||
|
||||
/** @brief Return test settings where inconclusive is true */
|
||||
static Settings testSettings()
|
||||
{
|
||||
return Settings(true);
|
||||
}
|
||||
|
||||
/** @brief Is --debug given? */
|
||||
bool _debug;
|
||||
|
||||
/** @brief Is --all given? */
|
||||
bool _showAll;
|
||||
/** @brief Inconclusive checks - for debugging of Cppcheck */
|
||||
const bool inconclusive;
|
||||
|
||||
/** @brief Is --style given? */
|
||||
bool _checkCodingStyle;
|
||||
|
|
|
@ -53,8 +53,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for buffer overruns..
|
||||
Settings settings;
|
||||
settings._showAll = showAll;
|
||||
Settings settings(showAll ? Settings::testSettings() : Settings());
|
||||
settings._checkCodingStyle = true;
|
||||
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
|
|
|
@ -417,9 +417,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check..
|
||||
Settings settings;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._checkCodingStyle = true;
|
||||
settings._showAll = true;
|
||||
CheckClass checkClass(&tokenizer, &settings, this);
|
||||
checkClass.operatorEqToSelf();
|
||||
}
|
||||
|
@ -1392,8 +1391,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
Settings settings(Settings::testSettings());
|
||||
CheckClass checkClass(&tokenizer, &settings, this);
|
||||
checkClass.constructors();
|
||||
}
|
||||
|
@ -2108,9 +2106,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check..
|
||||
Settings settings;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._checkCodingStyle = true;
|
||||
settings._showAll = true;
|
||||
CheckClass checkClass(&tokenizer, &settings, this);
|
||||
checkClass.thisSubtraction();
|
||||
}
|
||||
|
|
|
@ -46,9 +46,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check class constructors..
|
||||
Settings settings;
|
||||
Settings settings(showAll ? Settings::testSettings() : Settings());
|
||||
settings._checkCodingStyle = true;
|
||||
settings._showAll = showAll;
|
||||
CheckClass checkClass(&tokenizer, &settings, this);
|
||||
checkClass.constructors();
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for dangerous functions..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
Settings settings(Settings::testSettings());
|
||||
CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
|
||||
checkDangerousFunctions.dangerousFunctions();
|
||||
}
|
||||
|
|
|
@ -46,8 +46,7 @@ private:
|
|||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings._showAll = all;
|
||||
Settings settings(all ? Settings::testSettings() : Settings());
|
||||
settings._checkCodingStyle = style;
|
||||
|
||||
// Check for unsigned divisions..
|
||||
|
|
|
@ -47,8 +47,7 @@ private:
|
|||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
Settings settings(Settings::testSettings());
|
||||
|
||||
// Check for unused variables..
|
||||
CheckOther checkOther(&tokenizer, &settings, this);
|
||||
|
|
|
@ -212,9 +212,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
Settings settings;
|
||||
Settings settings(showAll ? Settings::testSettings() : Settings());
|
||||
settings._debug = true;
|
||||
settings._showAll = showAll;
|
||||
tokenizer.fillFunctionList();
|
||||
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
|
||||
checkMemoryLeak.check();
|
||||
|
@ -601,8 +600,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
settings._showAll = all;
|
||||
Settings settings(all ? Settings::testSettings() : Settings());
|
||||
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL);
|
||||
all = false;
|
||||
checkMemoryLeak.simplifycode(tokens, all);
|
||||
|
@ -2143,9 +2141,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
Settings settings;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._debug = true;
|
||||
settings._showAll = true;
|
||||
|
||||
{
|
||||
std::istringstream istr(_autoDealloc);
|
||||
|
@ -2715,9 +2712,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
Settings settings;
|
||||
Settings settings(showAll ? Settings::testSettings() : Settings());
|
||||
settings._debug = true;
|
||||
settings._showAll = showAll;
|
||||
tokenizer.fillFunctionList();
|
||||
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||
checkMemoryLeak.check();
|
||||
|
|
|
@ -3435,8 +3435,7 @@ private:
|
|||
void checkSimplifyTypedef(const char code[])
|
||||
{
|
||||
// Tokenize..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._checkCodingStyle = true;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
|
@ -4046,8 +4045,7 @@ private:
|
|||
void checkSimplifyEnum(const char code[])
|
||||
{
|
||||
// Tokenize..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._checkCodingStyle = true;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
|
|
|
@ -91,9 +91,8 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check..
|
||||
Settings settings;
|
||||
Settings settings(Settings::testSettings());
|
||||
settings._checkCodingStyle = true;
|
||||
settings._showAll = true;
|
||||
CheckStl checkStl;
|
||||
checkStl.runSimplifiedChecks(&tokenizer, &settings, this);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue