From 30ee9ba6e45f5ddcb264ab6bdd60e74ba7b3050f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 10 Apr 2011 13:23:45 +0200 Subject: [PATCH] Added Settings::stupid flag that can be used to hide checking that generates false positives. --- lib/checkbufferoverrun.cpp | 4 ++-- lib/checkclass.cpp | 2 +- lib/checkmemoryleak.cpp | 6 +++--- lib/checkother.cpp | 2 +- lib/preprocessor.cpp | 2 +- lib/settings.cpp | 1 + lib/settings.h | 7 +++++++ test/testbufferoverrun.cpp | 4 ++-- test/testclass.cpp | 2 +- test/testmemleak.cpp | 7 +++---- test/testother.cpp | 2 +- 11 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 34abf1f4b..19d711252 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1122,8 +1122,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo { if (!Token::Match(tok2, "%varid% [ %any% ] = 0 ;", tok->tokAt(2)->varId())) { - // this is currently inconclusive. See TestBufferOverrun::terminateStrncpy3 - if (_settings->inconclusive) + // this is currently 'stupid'. See TestBufferOverrun::terminateStrncpy3 + if (_settings->stupid) terminateStrncpyError(tok); } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a472a4a45..7e0c4ff0a 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1118,7 +1118,7 @@ void CheckClass::virtualDestructor() // * base class doesn't have virtual destructor // * derived class has non-empty destructor // * base class is deleted - if (!_settings->inconclusive) + if (!_settings->stupid) return; createSymbolDatabase(); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 92526167c..0a549ed5d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -774,7 +774,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listinconclusive) ? 0 : "callfunc"; + return (eq || _settings->stupid) ? 0 : "callfunc"; } } @@ -2024,7 +2024,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } // Remove the "if break|continue ;" that follows "dealloc ; alloc ;" - if (! _settings->inconclusive && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;")) + if (! _settings->stupid && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;")) { tok2 = tok2->tokAt(3); Token::eraseTokens(tok2, tok2->tokAt(3)); @@ -2290,7 +2290,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } // If "--all" is given, remove all "callfunc".. - if (done && _settings->inconclusive) + if (done && _settings->stupid) { for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7db77b140..3e36559c9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -354,7 +354,7 @@ void CheckOther::checkRedundantAssignmentInSwitch() void CheckOther::checkSwitchCaseFallThrough() { - if (!(_settings->_checkCodingStyle && _settings->inconclusive)) + if (!(_settings->_checkCodingStyle && _settings->stupid)) return; const char switchPattern[] = "switch ("; diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c392241c6..0586ef496 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -477,7 +477,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri // First check for a "fall through" comment match, but only // add a suppression if the next token is 'case' or 'default' - if (_settings->_checkCodingStyle && _settings->inconclusive && fallThroughComment) + if (_settings->_checkCodingStyle && _settings->stupid && fallThroughComment) { std::string::size_type j = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz", i); std::string tok = str.substr(i, j - i); diff --git a/lib/settings.cpp b/lib/settings.cpp index 4a0d7dcd9..1143c5f8a 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -43,6 +43,7 @@ Settings::Settings() _append = ""; _terminate = false; inconclusive = false; + stupid = false; test_2_pass = false; reportProgress = false; ifcfg = false; diff --git a/lib/settings.h b/lib/settings.h index bd03536d5..20649d8a6 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -58,6 +58,13 @@ public: /** @brief Inconclusive checks */ bool inconclusive; + /** + * @brief enables stupid checks that generates false positives because they are not clever enough. + * This flag should only be used temporarily by the check until it is fixed. + * There is no way to enable this flag from the command line. + */ + bool stupid; + /** @brief Is --style given? */ bool _checkCodingStyle; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 19706f8cf..d9ce169e7 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -36,13 +36,13 @@ private: - void check(const char code[], bool inconclusive = true) + void check(const char code[], bool stupid = true) { // Clear the error buffer.. errout.str(""); Settings settings; - settings.inconclusive = inconclusive; + settings.stupid = stupid; settings._checkCodingStyle = true; // Tokenize.. diff --git a/test/testclass.cpp b/test/testclass.cpp index c0b4a1684..8315cfc96 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -1382,7 +1382,7 @@ private: errout.str(""); Settings settings; - settings.inconclusive = true; + settings.stupid = true; // Tokenize.. Tokenizer tokenizer(&settings, this); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index bcb458865..341beeb2e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -127,13 +127,13 @@ public: { } private: - void check(const char code[], bool inconclusive = false) + void check(const char code[], bool stupid = false) { // Clear the error buffer.. errout.str(""); Settings settings; - settings.inconclusive = inconclusive; + settings.stupid = stupid; // Tokenize.. Tokenizer tokenizer(&settings, this); @@ -2994,7 +2994,7 @@ private: errout.str(""); Settings settings; - settings.inconclusive = true; + settings.stupid = true; // Tokenize.. Tokenizer tokenizer(&settings, this); @@ -3707,7 +3707,6 @@ private: /** * Tokenize and execute leak check for given code * @param code Source code - * @param inconclusive inconclusive checking */ void check(const char code[]) { diff --git a/test/testother.cpp b/test/testother.cpp index b42097501..77f74ee9a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -193,7 +193,7 @@ private: Settings settings; settings._checkCodingStyle = true; - settings.inconclusive = true; + settings.stupid = true; // Preprocess file.. Preprocessor preprocessor(&settings, this);