diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 68c901d18..b8afd39c1 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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_showAll) + if (!_settings->inconclusive) continue; unsigned int parlevel = 0, par = 0; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 38b571aaa..4d34868b7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; diff --git a/lib/checkclass.h b/lib/checkclass.h index b053cccbc..e08eb535f 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -63,7 +63,7 @@ public: checkClass.operatorEq(); checkClass.privateFunctions(); checkClass.operatorEqRetRefThis(); - if (settings->_showAll) + if (settings->inconclusive) { checkClass.thisSubtraction(); checkClass.operatorEqToSelf(); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 06fa81489..0c3cfb2d3 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -603,7 +603,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list_showAll) ? 0 : "callfunc"; + return (_settings && _settings->inconclusive) ? 0 : "callfunc"; } } @@ -800,7 +800,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listtokAt(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::vectorisAutoDealloc(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_showAll) + if (!_settings->inconclusive) return; const std::string varname = tokVarname->strAt(0); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 025f83790..9ff491e31 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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); diff --git a/lib/checkother.h b/lib/checkother.h index 7d4aa5c37..e3936bbdb 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -73,7 +73,7 @@ public: checkOther.checkConstantFunctionParameter(); checkOther.checkIncompleteStatement(); checkOther.unreachableCode(); - if (settings->_showAll) + if (settings->inconclusive) { checkOther.postIncrement(); } diff --git a/lib/checkstl.h b/lib/checkstl.h index aac50f3f6..7aad5f910 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -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(); } } diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 6dce504b7..7d5712797 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -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; diff --git a/lib/settings.cpp b/lib/settings.cpp old mode 100755 new mode 100644 index dfeeed57c..2d96d6d5e --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -24,9 +24,9 @@ #include 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 id; id.insert("exceptNew"); diff --git a/lib/settings.h b/lib/settings.h index 9a69e3004..080958c74 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -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; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 91613c6a8..9bf1004b5 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 73b0b4fea..72bd56641 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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(); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index eec6e4b34..d3d88feeb 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -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(); } diff --git a/test/testdangerousfunctions.cpp b/test/testdangerousfunctions.cpp index 3d78e1ab1..30a4f408c 100644 --- a/test/testdangerousfunctions.cpp +++ b/test/testdangerousfunctions.cpp @@ -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(); } diff --git a/test/testdivision.cpp b/test/testdivision.cpp index 5dc1d0297..131283e34 100644 --- a/test/testdivision.cpp +++ b/test/testdivision.cpp @@ -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.. diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 9983b6e1d..fae378a75 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 4307ca231..a08538414 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e2783b13f..481221938 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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); diff --git a/test/teststl.cpp b/test/teststl.cpp index 906946d8c..9ad0ef3af 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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); }