From 92a1e9e76e903b570ba1b0d04128b425a48789d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 Oct 2010 14:41:00 +0200 Subject: [PATCH] Severities: Added 'warning' and 'performance' severities. No changes to the command line options nor to the XML format. Ticket: #2106 --- lib/checkbufferoverrun.cpp | 6 +-- lib/checkclass.cpp | 9 +++-- lib/checkexceptionsafety.h | 2 +- lib/checkmemoryleak.cpp | 2 +- lib/checkobsoletefunctions.cpp | 2 + lib/checkother.cpp | 24 +++++------ lib/checkpostfixoperator.cpp | 2 +- lib/checkstl.cpp | 8 ++-- lib/errorlogger.cpp | 2 +- lib/errorlogger.h | 10 ++++- test/testbufferoverrun.cpp | 12 +++--- test/testcharvar.cpp | 8 ++-- test/testclass.cpp | 62 ++++++++++++++--------------- test/testconstructors.cpp | 50 +++++++++++------------ test/testcppcheck.cpp | 4 +- test/testexceptionsafety.cpp | 2 +- test/testincompletestatement.cpp | 4 +- test/testmemleak.cpp | 4 +- test/testother.cpp | 68 ++++++++++++++++---------------- test/testpostfixoperator.cpp | 22 +++++------ test/teststl.cpp | 16 ++++---- 21 files changed, 165 insertions(+), 154 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 7a04ff024..e64617ec2 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -117,7 +117,7 @@ void CheckBufferOverrun::strncatUsage(const Token *tok) if (_settings && !_settings->_checkCodingStyle) return; - reportError(tok, Severity::style, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append"); + reportError(tok, Severity::warning, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append"); } void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what) @@ -129,13 +129,13 @@ void CheckBufferOverrun::sizeArgumentAsChar(const Token *tok) { if (_settings && !_settings->_checkCodingStyle) return; - reportError(tok, Severity::style, "sizeArgumentAsChar", "The size argument is given as a char constant"); + reportError(tok, Severity::warning, "sizeArgumentAsChar", "The size argument is given as a char constant"); } void CheckBufferOverrun::terminateStrncpyError(const Token *tok) { - reportError(tok, Severity::style, "terminateStrncpy", "After a strncpy() the buffer should be zero-terminated"); + reportError(tok, Severity::warning, "terminateStrncpy", "After a strncpy() the buffer should be zero-terminated"); } void CheckBufferOverrun::cmdLineArgsError(const Token *tok) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 892a78dfd..f407dcaa3 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1888,7 +1888,7 @@ void CheckClass::virtualDestructor() void CheckClass::thisSubtractionError(const Token *tok) { - reportError(tok, Severity::style, "thisSubtraction", "Suspicious pointer subtraction"); + reportError(tok, Severity::warning, "thisSubtraction", "Suspicious pointer subtraction"); } void CheckClass::thisSubtraction() @@ -2272,17 +2272,18 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st void CheckClass::noConstructorError(const Token *tok, const std::string &classname, bool isStruct) { + // For performance reasons the constructor might be intentionally missing. Therefore this is not a "warning" reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized."); } void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname) { - reportError(tok, Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'"); + reportError(tok, Severity::warning, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'"); } void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname) { - reportError(tok, Severity::style, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'"); + reportError(tok, Severity::warning, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'"); } void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname) @@ -2317,5 +2318,5 @@ void CheckClass::operatorEqRetRefThisError(const Token *tok) void CheckClass::operatorEqToSelfError(const Token *tok) { - reportError(tok, Severity::style, "operatorEqToSelf", "'operator=' should check for assignment to self"); + reportError(tok, Severity::warning, "operatorEqToSelf", "'operator=' should check for assignment to self"); } diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index e969fe159..933393998 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -69,7 +69,7 @@ private: /** Don't throw exceptions in destructors */ void destructorsError(const Token * const tok) { - reportError(tok, Severity::style, "exceptThrowInDestructor", "Throwing exception in destructor"); + reportError(tok, Severity::error, "exceptThrowInDestructor", "Throwing exception in destructor"); } void deallocThrowError(const Token * const tok, const std::string &varname) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 7f04bf744..362b3fa44 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2751,7 +2751,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Token *classtok, const u void CheckMemoryLeakInClass::publicAllocationError(const Token *tok, const std::string &varname) { - reportError(tok, Severity::style, "publicAllocationError", "Possible leak in public function. The pointer '" + varname + "' is not deallocated before it is allocated."); + reportError(tok, Severity::warning, "publicAllocationError", "Possible leak in public function. The pointer '" + varname + "' is not deallocated before it is allocated."); } diff --git a/lib/checkobsoletefunctions.cpp b/lib/checkobsoletefunctions.cpp index 9e3f38a03..ff0137ef6 100644 --- a/lib/checkobsoletefunctions.cpp +++ b/lib/checkobsoletefunctions.cpp @@ -43,6 +43,8 @@ void CheckObsoleteFunctions::obsoleteFunctions() { if (tok->strAt(1) == it->first && tok->strAt(2) == "(" && tok->tokAt(1)->varId() == 0 && !tok->tokAt(0)->isName() && !Token::Match(tok, ".|::|:|,")) { + // If checking an old code base it might be uninteresting to update obsolete functions. + // Therefore this is "style" reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second); break; } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e1c405916..29e48ff42 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -383,7 +383,7 @@ void CheckOther::invalidScanf() void CheckOther::invalidScanfError(const Token *tok) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "invalidscanf", "scanf without field width limits can crash with huge input data\n" "To fix this error message add a field width specifier:\n" " %s => %20s\n" @@ -3952,22 +3952,22 @@ void CheckOther::unusedStructMemberError(const Token *tok, const std::string &st void CheckOther::passedByValueError(const Token *tok, const std::string &parname) { - reportError(tok, Severity::style, "passedByValue", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead, to make it faster."); + reportError(tok, Severity::performance, "passedByValue", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead, to make it faster."); } void CheckOther::constStatementError(const Token *tok, const std::string &type) { - reportError(tok, Severity::style, "constStatement", "Redundant code: Found a statement that begins with " + type + " constant"); + reportError(tok, Severity::warning, "constStatement", "Redundant code: Found a statement that begins with " + type + " constant"); } void CheckOther::charArrayIndexError(const Token *tok) { - reportError(tok, Severity::style, "charArrayIndex", "Warning - using char variable as array index"); + reportError(tok, Severity::warning, "charArrayIndex", "Warning - using char variable as array index"); } void CheckOther::charBitOpError(const Token *tok) { - reportError(tok, Severity::style, "charBitOp", "Warning - using char variable in bit operation"); + reportError(tok, Severity::warning, "charBitOp", "Warning - using char variable in bit operation"); } void CheckOther::variableScopeError(const Token *tok, const std::string &varname) @@ -4055,12 +4055,12 @@ void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_n { if (isTestForEmpty) { - reportError(tok, Severity::style, + reportError(tok, Severity::performance, "emptyStringTest", "Empty string test can be simplified to \"*" + var_name + " == '\\0'\""); } else { - reportError(tok, Severity::style, + reportError(tok, Severity::performance, "emptyStringTest", "Non-empty string test can be simplified to \"*" + var_name + " != '\\0'\""); } } @@ -4084,7 +4084,7 @@ void CheckOther::sizeofsizeof() void CheckOther::sizeofsizeofError(const Token *tok) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "sizeofsizeof", "Suspicious code 'sizeof sizeof ..', most likely there should only be one sizeof. The current code is equivalent to 'sizeof(size_t)'."); } @@ -4119,25 +4119,25 @@ void CheckOther::sizeofCalculation() void CheckOther::sizeofCalculationError(const Token *tok) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "sizeofCalculation", "Found calculation inside sizeof()"); } void CheckOther::redundantAssignmentInSwitchError(const Token *tok, const std::string &varname) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "redundantAssignInSwitch", "Redundant assignment of \"" + varname + "\" in switch"); } void CheckOther::selfAssignmentError(const Token *tok, const std::string &varname) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "selfAssignment", "Redundant assignment of \"" + varname + "\" to itself"); } void CheckOther::assignmentInAssertError(const Token *tok, const std::string &varname) { - reportError(tok, Severity::style, + reportError(tok, Severity::warning, "assignmentInAssert", "Assert statement modifies '" + varname + "'. If the modification is needed in release builds there is a bug."); } diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index d52531ab5..992962fa9 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -90,5 +90,5 @@ void CheckPostfixOperator::postfixOperator() void CheckPostfixOperator::postfixOperatorError(const Token *tok) { - reportError(tok, Severity::style, "postfixOperator", "You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators"); + reportError(tok, Severity::performance, "postfixOperator", "You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators"); } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 66b8d30d4..9698b6b14 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -723,9 +723,9 @@ void CheckStl::if_find() void CheckStl::if_findError(const Token *tok, bool str) { if (str) - reportError(tok, Severity::style, "stlIfStrFind", "Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string."); + reportError(tok, Severity::warning, "stlIfStrFind", "Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string."); else - reportError(tok, Severity::style, "stlIfFind", "Suspicious condition. The result of find is an iterator, but it is not properly checked."); + reportError(tok, Severity::warning, "stlIfFind", "Suspicious condition. The result of find is an iterator, but it is not properly checked."); } @@ -808,7 +808,7 @@ void CheckStl::sizeError(const Token *tok) { const std::string varname(tok ? tok->str().c_str() : "list"); const bool verbose(_settings ? _settings->_verbose : true); - reportError(tok, Severity::style, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : "")); + reportError(tok, Severity::performance, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : "")); } @@ -914,7 +914,7 @@ void CheckStl::missingComparisonError(const Token *incrementToken1, const Token << " and then at line " << incrementToken2->linenr() << ". The loop might unintentionally skip an element in the container. There is no comparison between these increments to prevent that the iterator is incremented beyond the end."; - reportError(incrementToken1, Severity::style, "StlMissingComparison", errmsg.str()); + reportError(incrementToken1, Severity::warning, "StlMissingComparison", errmsg.str()); } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 6ca014d00..bf9d2adf8 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -157,7 +157,7 @@ std::string ErrorLogger::ErrorMessage::toXML() const xml << " line=\"" << _callStack.back().line << "\""; } xml << " id=\"" << _id << "\""; - xml << " severity=\"" << Severity::toString(_severity) << "\""; + xml << " severity=\"" << (_severity == Severity::error ? "error" : "style") << "\""; xml << " msg=\"" << stringToXml(_msg) << "\""; xml << "/>"; return xml.str(); diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 54356b696..64b7e1384 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -33,7 +33,7 @@ class Tokenizer; class Severity { public: - enum SeverityType { none, error, style, debug }; + enum SeverityType { none, error, warning, style, performance, debug }; static std::string toString(SeverityType severity) { switch (severity) @@ -42,8 +42,12 @@ public: return ""; case error: return "error"; + case warning: + return "warning"; case style: return "style"; + case performance: + return "performance"; case debug: return "debug"; }; @@ -57,8 +61,12 @@ public: return none; if (severity == "error") return error; + if (severity == "warning") + return warning; if (severity == "style") return style; + if (severity == "performance") + return performance; if (severity == "debug") return debug; return none; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 439b171e7..57835a4f7 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1894,7 +1894,7 @@ private: " strncpy(str, a, 10);\n" " strncat(str, b, 10);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str()); } void strncat2() @@ -1904,7 +1904,7 @@ private: " char str[5];\n" " strncat(str, a, 5);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str()); } void strncat3() @@ -2132,7 +2132,7 @@ private: " char s[10];\n" " memset(s, 5, '*');\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) The size argument is given as a char constant\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The size argument is given as a char constant\n", errout.str()); check("void foo()\n" "{\n" @@ -2308,7 +2308,7 @@ private: " strncpy(baz, bar, sizeof(baz));\n" " bar[99] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) After a strncpy() the buffer should be zero-terminated\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) After a strncpy() the buffer should be zero-terminated\n", errout.str()); // Test with invalid code that there is no segfault check("char baz[100];\n" @@ -2323,7 +2323,7 @@ private: " foo(baz);\n" " foo(baz);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) After a strncpy() the buffer should be zero-terminated\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) After a strncpy() the buffer should be zero-terminated\n", errout.str()); } void terminateStrncpy2() @@ -2335,7 +2335,7 @@ private: " bar[99] = 0;\n" " return baz;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) After a strncpy() the buffer should be zero-terminated\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) After a strncpy() the buffer should be zero-terminated\n", errout.str()); } void recursive_long_time() diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 6e0ee19d2..b9b82d1b8 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -75,20 +75,20 @@ private: " char ch = 0x80;\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Warning - using char variable as array index\n", errout.str()); check("void foo()\n" "{\n" " signed char ch = 0x80;\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Warning - using char variable as array index\n", errout.str()); check("void foo(char ch)\n" "{\n" " buf[ch] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Warning - using char variable as array index\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Warning - using char variable as array index\n", errout.str()); } @@ -100,7 +100,7 @@ private: " char ch;\n" " result = a | ch;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable in bit operation\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Warning - using char variable in bit operation\n", errout.str()); } void bitop2() diff --git a/test/testclass.cpp b/test/testclass.cpp index a40d130d9..9588f6631 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -516,7 +516,7 @@ private: " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -571,7 +571,7 @@ private: " s = strdup(a.s);\n" " return *this;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self\n", errout.str()); // ticket #1224 checkOpertorEqToSelf( @@ -658,7 +658,7 @@ private: " }\n" " };\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -729,7 +729,7 @@ private: " s = strdup(b.s);\n" " return *this;\n" " }\n"); - ASSERT_EQUALS("[test.cpp:11]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self\n", errout.str()); } void operatorEqToSelf3() @@ -1155,7 +1155,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1172,7 +1172,7 @@ private: " strcpy(data, a.data);\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1188,7 +1188,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1205,7 +1205,7 @@ private: " *data = *a.data;\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); } void operatorEqToSelf7() @@ -1489,7 +1489,7 @@ private: " ECODES _code;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) Member variable not initialized in the constructor 'Fred::_code'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable not initialized in the constructor 'Fred::_code'\n", errout.str()); checkUninitVar("class A{};\n" @@ -1501,7 +1501,7 @@ private: "private:\n" " float f;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Member variable not initialized in the constructor 'B::f'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable not initialized in the constructor 'B::f'\n", errout.str()); checkUninitVar("class C\n" "{\n" @@ -1555,7 +1555,7 @@ private: " };\n" " Bar bars[2];\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Foo::bars'\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Foo::bars'\n", errout.str()); ASSERT_EQUALS("", errout.str()); // So we notice if something is reported. } @@ -1636,7 +1636,7 @@ private: " }\n" " return *this;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='\n", errout.str()); } void uninitVar9() // ticket #1730 @@ -1651,7 +1651,7 @@ private: "{\n" " SetMinSize( wxSize( 48,48 ) );\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Prefs::xasd'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Prefs::xasd'\n", errout.str()); } void uninitVar10() // ticket #1993 @@ -1664,7 +1664,7 @@ private: " int var2;\n" "};\n" "A::A() : var1(0) { }\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'A::var2'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable not initialized in the constructor 'A::var2'\n", errout.str()); } void uninitVar11() @@ -1676,7 +1676,7 @@ private: " int var;\n" "};\n" "A::A(int a) { }\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'A::var'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'A::var'\n", errout.str()); } void uninitVar12() // ticket #2078 @@ -1693,8 +1693,8 @@ private: " {}\n" " int x, y;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Point::x'\n" - "[test.cpp:4]: (style) Member variable not initialized in the constructor 'Point::y'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Point::x'\n" + "[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Point::y'\n", errout.str()); } void uninitVarArray1() @@ -1707,7 +1707,7 @@ private: "private:\n" " char name[255];\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'John::name'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'John::name'\n", errout.str()); checkUninitVar("class John\n" "{\n" @@ -1754,7 +1754,7 @@ private: " John() { }\n" " A *a[5];\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'John::a'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable not initialized in the constructor 'John::a'\n", errout.str()); } void uninitVarArray2() @@ -1877,7 +1877,7 @@ private: "private:\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); // Unknown non-member function checkUninitVar("class Fred\n" @@ -1887,7 +1887,7 @@ private: "private:\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); // Unknown non-member function checkUninitVar("class ABC { };\n" @@ -1898,7 +1898,7 @@ private: "private:\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } @@ -1913,7 +1913,7 @@ private: " unsigned int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } void uninitVarStream() @@ -1979,7 +1979,7 @@ private: " Foo(int _i) { }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); } @@ -2030,7 +2030,7 @@ private: " Fred() { }\n" "};\n" "#endfile\n"); - ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[fred.h:6]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } void uninitVarHeader3() @@ -2044,7 +2044,7 @@ private: " Fred() { }\n" "};\n" "#endfile\n"); - ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[fred.h:6]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } // Borland C++: No FP for published pointers - they are automaticly initialized @@ -2181,7 +2181,7 @@ private: " Foo() { }\n" "};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:11]: (style) Member variable not initialized in the constructor 'Foo::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11]: (warning) Member variable not initialized in the constructor 'Foo::i'\n", errout.str()); checkUninitVar("namespace n1\n" "{\n" @@ -2423,20 +2423,20 @@ private: void this_subtraction() { checkThisSubtraction("; this-x ;"); - ASSERT_EQUALS("[test.cpp:1]: (style) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction\n", errout.str()); checkThisSubtraction("; *this = *this-x ;"); ASSERT_EQUALS("", errout.str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction\n", errout.str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;\n" "this-x ;\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious pointer subtraction\n" - "[test.cpp:3]: (style) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction\n" + "[test.cpp:3]: (warning) Suspicious pointer subtraction\n", errout.str()); } void checkConst(const char code[], const Settings *s = 0) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index d913270fc..a9ec365c7 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -136,7 +136,7 @@ private: " Fred() { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); check("struct Fred\n" "{\n" @@ -157,7 +157,7 @@ private: " Fred() { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } @@ -191,7 +191,7 @@ private: "};\n" "Fred::Fred()\n" "{ }\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); check("struct Fred\n" "{\n" @@ -218,7 +218,7 @@ private: "};\n" "Fred::Fred()\n" "{ }\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } @@ -237,7 +237,7 @@ private: "{\n" " i = _i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); check("struct Fred\n" "{\n" @@ -251,7 +251,7 @@ private: "{\n" " i = _i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::i'\n", errout.str()); } @@ -392,7 +392,7 @@ private: " void operator=(const Fred &fred) { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); check("struct Fred\n" "{\n" @@ -400,7 +400,7 @@ private: " void operator=(const Fred &fred) { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); } void initvar_operator_eq3() @@ -622,7 +622,7 @@ private: "};\n" "Fred::Fred()\n" "{ }"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::s'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::s'\n", errout.str()); check("struct Fred\n" "{\n" @@ -649,7 +649,7 @@ private: "};\n" "Fred::Fred()\n" "{ }"); - ASSERT_EQUALS("[test.cpp:6]: (style) Member variable not initialized in the constructor 'Fred::s'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable not initialized in the constructor 'Fred::s'\n", errout.str()); } @@ -689,7 +689,7 @@ private: " Fred() { };\n" " Fred(const Fred &) { };\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::var'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::var'\n", errout.str()); check("class Fred\n" "{\n" @@ -701,7 +701,7 @@ private: "};\n" "Fred::Fred() { };\n" "Fred::Fred(const Fred &) { };\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) Member variable not initialized in the constructor 'Fred::var'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable not initialized in the constructor 'Fred::var'\n", errout.str()); } void initvar_nested_constructor() // ticket #1375 @@ -729,10 +729,10 @@ private: "A::B::B(){}\n" "A::B::C::C(){}\n" "A::B::C::D::D(){}\n"); - ASSERT_EQUALS("[test.cpp:20]: (style) Member variable not initialized in the constructor 'A::a'\n" - "[test.cpp:21]: (style) Member variable not initialized in the constructor 'B::b'\n" - "[test.cpp:22]: (style) Member variable not initialized in the constructor 'C::c'\n" - "[test.cpp:23]: (style) Member variable not initialized in the constructor 'D::d'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable not initialized in the constructor 'A::a'\n" + "[test.cpp:21]: (warning) Member variable not initialized in the constructor 'B::b'\n" + "[test.cpp:22]: (warning) Member variable not initialized in the constructor 'C::c'\n" + "[test.cpp:23]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str()); check("class A {\n" "public:\n" @@ -757,10 +757,10 @@ private: "A::B::B(){}\n" "A::B::C::C(){}\n" "A::B::C::D::D(const A::B::C::D & d){}\n"); - ASSERT_EQUALS("[test.cpp:20]: (style) Member variable not initialized in the constructor 'A::a'\n" - "[test.cpp:21]: (style) Member variable not initialized in the constructor 'B::b'\n" - "[test.cpp:22]: (style) Member variable not initialized in the constructor 'C::c'\n" - "[test.cpp:23]: (style) Member variable not initialized in the constructor 'D::d'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable not initialized in the constructor 'A::a'\n" + "[test.cpp:21]: (warning) Member variable not initialized in the constructor 'B::b'\n" + "[test.cpp:22]: (warning) Member variable not initialized in the constructor 'C::c'\n" + "[test.cpp:23]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str()); check("class A {\n" "public:\n" @@ -786,10 +786,10 @@ private: "A::B::B(){}\n" "A::B::C::C(){}\n" "A::B::C::D::D(const A::B::C::D::E & e){}\n"); - ASSERT_EQUALS("[test.cpp:21]: (style) Member variable not initialized in the constructor 'A::a'\n" - "[test.cpp:22]: (style) Member variable not initialized in the constructor 'B::b'\n" - "[test.cpp:23]: (style) Member variable not initialized in the constructor 'C::c'\n" - "[test.cpp:24]: (style) Member variable not initialized in the constructor 'D::d'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:21]: (warning) Member variable not initialized in the constructor 'A::a'\n" + "[test.cpp:22]: (warning) Member variable not initialized in the constructor 'B::b'\n" + "[test.cpp:23]: (warning) Member variable not initialized in the constructor 'C::c'\n" + "[test.cpp:24]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str()); } void initvar_destructor() @@ -821,7 +821,7 @@ private: "\n" "void Fred::operator=(const Fred &f)\n" "{ }", true); - ASSERT_EQUALS("[test.cpp:13]: (style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str()); } }; diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index a8b4689a4..fec19ae85 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -378,7 +378,7 @@ private: // Test the errorlogger.. ErrorLogger::ErrorMessage errorMessage; errorMessage._msg = "abef"; - ASSERT_EQUALS("", errorMessage.toXML()); + ASSERT_EQUALS("", errorMessage.toXML()); } @@ -389,7 +389,7 @@ private: loc.setfile("ab/cd/../ef.h"); errorMessage._callStack.push_back(loc); const std::string fname(Path::toNativeSeparators("ab/ef.h")); - ASSERT_EQUALS("", errorMessage.toXML()); + ASSERT_EQUALS("", errorMessage.toXML()); ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString()); } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 0e1f72b22..81f3f1004 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -62,7 +62,7 @@ private: "{\n" " throw e;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Throwing exception in destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", errout.str()); } void deallocThrow() diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 0918b5656..653584bdf 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -89,7 +89,7 @@ private: " \"abc\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant code: Found a statement that begins with string constant\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant\n", errout.str()); } void test3() @@ -124,7 +124,7 @@ private: " 50;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant code: Found a statement that begins with numeric constant\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant\n", errout.str()); } void test_numeric() diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e87756783..8557a602b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -3578,7 +3578,7 @@ private: " void xy()\n" " { s = malloc(100); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:9]: (style) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); check("class Fred\n" "{\n" @@ -3606,7 +3606,7 @@ private: " const Fred & operator = (const Fred &f)\n" " { s = malloc(100); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:9]: (style) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index 062606755..48c1b7396 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2417,19 +2417,19 @@ private: void passedByValue() { testPassedByValue("void f(const std::string str) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'str' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("class Foo;\nvoid f(const Foo foo) {}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Function parameter 'foo' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::string &str) {}"); ASSERT_EQUALS("", errout.str()); testPassedByValue("void f(const std::vector v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::vector v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::vector &v) {}"); ASSERT_EQUALS("", errout.str()); @@ -2438,16 +2438,16 @@ private: ASSERT_EQUALS("", errout.str()); testPassedByValue("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); testPassedByValue("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str()); } void mathfunctionCall1() @@ -2633,31 +2633,31 @@ private: " std::cout << str;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (performance) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); check("if (!strlen(str)) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); check("if (strlen(str) == 0) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); check("if (strlen(str)) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); check("if (strlen(str) > 0) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); check("if (strlen(str) != 0) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); check("if (0 != strlen(str)) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); check("if (0 == strlen(str)) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Empty string test can be simplified to \"*str == '\\0'\"\n", errout.str()); check("if (0 < strlen(str)) { }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (performance) Non-empty string test can be simplified to \"*str != '\\0'\"\n", errout.str()); } void fflushOnInputStreamTest() @@ -2681,13 +2681,13 @@ private: "{\n" " int i = sizeof sizeof char;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Suspicious code 'sizeof sizeof ..', most likely there should only be one sizeof. The current code is equivalent to 'sizeof(size_t)'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious code 'sizeof sizeof ..', most likely there should only be one sizeof. The current code is equivalent to 'sizeof(size_t)'.\n", errout.str()); } void sizeofCalculation() { check("sizeof(a+b)"); - ASSERT_EQUALS("[test.cpp:1]: (style) Found calculation inside sizeof()\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str()); check("sizeof(-a)"); ASSERT_EQUALS("", errout.str()); @@ -2709,7 +2709,7 @@ private: " y = 3;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) Redundant assignment of \"y\" in switch\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant assignment of \"y\" in switch\n", errout.str()); check("void foo()\n" "{\n" @@ -2724,7 +2724,7 @@ private: " y = 3;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Redundant assignment of \"y\" in switch\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) Redundant assignment of \"y\" in switch\n", errout.str()); check("void foo()\n" "{\n" @@ -2855,21 +2855,21 @@ private: " x = x;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Redundant assignment of \"x\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Redundant assignment of \"x\" to itself\n", errout.str()); check("void foo()\n" "{\n" " int x = x;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of \"x\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"x\" to itself\n", errout.str()); check("void foo()\n" "{\n" " std::string var = var = \"test\";\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of \"var\" to itself\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"var\" to itself\n", errout.str()); check("void foo()\n" "{\n" @@ -2893,8 +2893,8 @@ private: " fclose(file);\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) scanf without field width limits can crash with huge input data\n" - "[test.cpp:7]: (style) scanf without field width limits can crash with huge input data\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n" + "[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n", errout.str()); } void testScanf2() @@ -2910,8 +2910,8 @@ private: " fclose(file);\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) scanf without field width limits can crash with huge input data\n" - "[test.cpp:7]: (style) scanf without field width limits can crash with huge input data\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n" + "[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n", errout.str()); } void trac1132() @@ -3097,7 +3097,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); check("void f() {\n" " int a = 0;\n" @@ -3114,7 +3114,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:4]: (style) Assert statement modifies 'b'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Assert statement modifies 'b'. If the modification is needed in release builds there is a bug.\n", errout.str()); check("void f() {\n" " int a = 0;\n" @@ -3122,7 +3122,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); check("void f() {\n" " int a = 0;\n" @@ -3130,7 +3130,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); check("void f() {\n" " int a = 0;\n" @@ -3138,7 +3138,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); check("void f() {\n" " int a = 0;\n" @@ -3146,7 +3146,7 @@ private: " return a;\n" "}\n" ); - ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str()); } }; diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 29cfc7398..a35e88300 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -100,7 +100,7 @@ private: " std::cout << k << std::endl;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -115,7 +115,7 @@ private: " std::cout << k << std::endl;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -131,7 +131,7 @@ private: " std::cout << k << std::endl;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" @@ -145,7 +145,7 @@ private: " std::cout << k << std::endl;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -198,7 +198,7 @@ private: " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -222,7 +222,7 @@ private: " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -263,7 +263,7 @@ private: " std::cout << k-- << std::endl;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -310,7 +310,7 @@ private: " v.clear();\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -327,7 +327,7 @@ private: " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:12]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -343,7 +343,7 @@ private: " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:11]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); check("\n" "#include \n" @@ -360,7 +360,7 @@ private: " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (style) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); + ASSERT_EQUALS("[test.cpp:12]: (performance) You should use ++ and -- as prefix whenever possible as these are more efficient than postfix operators\n", errout.str()); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 0503b567f..a1309ced0 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -954,7 +954,7 @@ private: "{\n" " if (s.find(12)) { }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n", errout.str()); // ok check("void f(std::set s)\n" @@ -973,7 +973,7 @@ private: "{\n" " if (std::find(a,b,c)) { }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n", errout.str()); // ok check("void f()\n" @@ -990,7 +990,7 @@ private: "{\n" " if (s.find(\"abc\")) { }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string.\n", errout.str()); } @@ -1001,28 +1001,28 @@ private: " std::list x;\n" " if (x.size() == 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (performance) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() != 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (performance) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() > 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (performance) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size()) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (performance) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" @@ -1063,7 +1063,7 @@ private: " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) The iterator is incremented at line 4 and then at line 2. The loop might unintentionally skip an element in the container. There is no comparison between these increments to prevent that the iterator is incremented beyond the end.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The iterator is incremented at line 4 and then at line 2. The loop might unintentionally skip an element in the container. There is no comparison between these increments to prevent that the iterator is incremented beyond the end.\n", errout.str()); } void missingInnerComparison2()