Merge branch 'master' of github.com:danmar/cppcheck
This commit is contained in:
commit
7d1995dfaa
|
@ -117,7 +117,7 @@ void CheckBufferOverrun::strncatUsage(const Token *tok)
|
||||||
if (_settings && !_settings->_checkCodingStyle)
|
if (_settings && !_settings->_checkCodingStyle)
|
||||||
return;
|
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)
|
void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what)
|
||||||
|
@ -129,13 +129,13 @@ void CheckBufferOverrun::sizeArgumentAsChar(const Token *tok)
|
||||||
{
|
{
|
||||||
if (_settings && !_settings->_checkCodingStyle)
|
if (_settings && !_settings->_checkCodingStyle)
|
||||||
return;
|
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)
|
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)
|
void CheckBufferOverrun::cmdLineArgsError(const Token *tok)
|
||||||
|
|
|
@ -1888,7 +1888,7 @@ void CheckClass::virtualDestructor()
|
||||||
|
|
||||||
void CheckClass::thisSubtractionError(const Token *tok)
|
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()
|
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)
|
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.");
|
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)
|
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)
|
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)
|
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)
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ private:
|
||||||
/** Don't throw exceptions in destructors */
|
/** Don't throw exceptions in destructors */
|
||||||
void destructorsError(const Token * const tok)
|
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)
|
void deallocThrowError(const Token * const tok, const std::string &varname)
|
||||||
|
|
|
@ -2751,7 +2751,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Token *classtok, const u
|
||||||
|
|
||||||
void CheckMemoryLeakInClass::publicAllocationError(const Token *tok, const std::string &varname)
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 (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);
|
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ void CheckOther::invalidScanf()
|
||||||
|
|
||||||
void CheckOther::invalidScanfError(const Token *tok)
|
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"
|
"invalidscanf", "scanf without field width limits can crash with huge input data\n"
|
||||||
"To fix this error message add a field width specifier:\n"
|
"To fix this error message add a field width specifier:\n"
|
||||||
" %s => %20s\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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
if (isTestForEmpty)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style,
|
reportError(tok, Severity::performance,
|
||||||
"emptyStringTest", "Empty string test can be simplified to \"*" + var_name + " == '\\0'\"");
|
"emptyStringTest", "Empty string test can be simplified to \"*" + var_name + " == '\\0'\"");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style,
|
reportError(tok, Severity::performance,
|
||||||
"emptyStringTest", "Non-empty string test can be simplified to \"*" + var_name + " != '\\0'\"");
|
"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)
|
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)'.");
|
"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)
|
void CheckOther::sizeofCalculationError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style,
|
reportError(tok, Severity::warning,
|
||||||
"sizeofCalculation", "Found calculation inside sizeof()");
|
"sizeofCalculation", "Found calculation inside sizeof()");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::redundantAssignmentInSwitchError(const Token *tok, const std::string &varname)
|
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");
|
"redundantAssignInSwitch", "Redundant assignment of \"" + varname + "\" in switch");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::selfAssignmentError(const Token *tok, const std::string &varname)
|
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");
|
"selfAssignment", "Redundant assignment of \"" + varname + "\" to itself");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::assignmentInAssertError(const Token *tok, const std::string &varname)
|
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.");
|
"assignmentInAssert", "Assert statement modifies '" + varname + "'. If the modification is needed in release builds there is a bug.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,5 +90,5 @@ void CheckPostfixOperator::postfixOperator()
|
||||||
|
|
||||||
void CheckPostfixOperator::postfixOperatorError(const Token *tok)
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -723,9 +723,9 @@ void CheckStl::if_find()
|
||||||
void CheckStl::if_findError(const Token *tok, bool str)
|
void CheckStl::if_findError(const Token *tok, bool str)
|
||||||
{
|
{
|
||||||
if (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
|
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 std::string varname(tok ? tok->str().c_str() : "list");
|
||||||
const bool verbose(_settings ? _settings->_verbose : true);
|
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()
|
<< " 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.";
|
<< ". 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ std::string ErrorLogger::ErrorMessage::toXML() const
|
||||||
xml << " line=\"" << _callStack.back().line << "\"";
|
xml << " line=\"" << _callStack.back().line << "\"";
|
||||||
}
|
}
|
||||||
xml << " id=\"" << _id << "\"";
|
xml << " id=\"" << _id << "\"";
|
||||||
xml << " severity=\"" << Severity::toString(_severity) << "\"";
|
xml << " severity=\"" << (_severity == Severity::error ? "error" : "style") << "\"";
|
||||||
xml << " msg=\"" << stringToXml(_msg) << "\"";
|
xml << " msg=\"" << stringToXml(_msg) << "\"";
|
||||||
xml << "/>";
|
xml << "/>";
|
||||||
return xml.str();
|
return xml.str();
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Tokenizer;
|
||||||
class Severity
|
class Severity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum SeverityType { none, error, style, debug };
|
enum SeverityType { none, error, warning, style, performance, debug };
|
||||||
static std::string toString(SeverityType severity)
|
static std::string toString(SeverityType severity)
|
||||||
{
|
{
|
||||||
switch (severity)
|
switch (severity)
|
||||||
|
@ -42,8 +42,12 @@ public:
|
||||||
return "";
|
return "";
|
||||||
case error:
|
case error:
|
||||||
return "error";
|
return "error";
|
||||||
|
case warning:
|
||||||
|
return "warning";
|
||||||
case style:
|
case style:
|
||||||
return "style";
|
return "style";
|
||||||
|
case performance:
|
||||||
|
return "performance";
|
||||||
case debug:
|
case debug:
|
||||||
return "debug";
|
return "debug";
|
||||||
};
|
};
|
||||||
|
@ -57,8 +61,12 @@ public:
|
||||||
return none;
|
return none;
|
||||||
if (severity == "error")
|
if (severity == "error")
|
||||||
return error;
|
return error;
|
||||||
|
if (severity == "warning")
|
||||||
|
return warning;
|
||||||
if (severity == "style")
|
if (severity == "style")
|
||||||
return style;
|
return style;
|
||||||
|
if (severity == "performance")
|
||||||
|
return performance;
|
||||||
if (severity == "debug")
|
if (severity == "debug")
|
||||||
return debug;
|
return debug;
|
||||||
return none;
|
return none;
|
||||||
|
|
|
@ -1894,7 +1894,7 @@ private:
|
||||||
" strncpy(str, a, 10);\n"
|
" strncpy(str, a, 10);\n"
|
||||||
" strncat(str, b, 10);\n"
|
" strncat(str, b, 10);\n"
|
||||||
"}\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()
|
void strncat2()
|
||||||
|
@ -1904,7 +1904,7 @@ private:
|
||||||
" char str[5];\n"
|
" char str[5];\n"
|
||||||
" strncat(str, a, 5);\n"
|
" strncat(str, a, 5);\n"
|
||||||
"}\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()
|
void strncat3()
|
||||||
|
@ -2132,7 +2132,7 @@ private:
|
||||||
" char s[10];\n"
|
" char s[10];\n"
|
||||||
" memset(s, 5, '*');\n"
|
" memset(s, 5, '*');\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2308,7 +2308,7 @@ private:
|
||||||
" strncpy(baz, bar, sizeof(baz));\n"
|
" strncpy(baz, bar, sizeof(baz));\n"
|
||||||
" bar[99] = 0;\n"
|
" bar[99] = 0;\n"
|
||||||
"}\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
|
// Test with invalid code that there is no segfault
|
||||||
check("char baz[100];\n"
|
check("char baz[100];\n"
|
||||||
|
@ -2323,7 +2323,7 @@ private:
|
||||||
" foo(baz);\n"
|
" foo(baz);\n"
|
||||||
" foo(baz);\n"
|
" foo(baz);\n"
|
||||||
"}\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()
|
void terminateStrncpy2()
|
||||||
|
@ -2335,7 +2335,7 @@ private:
|
||||||
" bar[99] = 0;\n"
|
" bar[99] = 0;\n"
|
||||||
" return baz;\n"
|
" return baz;\n"
|
||||||
"}\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()
|
void recursive_long_time()
|
||||||
|
|
|
@ -75,20 +75,20 @@ private:
|
||||||
" char ch = 0x80;\n"
|
" char ch = 0x80;\n"
|
||||||
" buf[ch] = 0;\n"
|
" buf[ch] = 0;\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" signed char ch = 0x80;\n"
|
" signed char ch = 0x80;\n"
|
||||||
" buf[ch] = 0;\n"
|
" buf[ch] = 0;\n"
|
||||||
"}\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"
|
check("void foo(char ch)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" buf[ch] = 0;\n"
|
" buf[ch] = 0;\n"
|
||||||
"}\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"
|
" char ch;\n"
|
||||||
" result = a | ch;\n"
|
" result = a | ch;\n"
|
||||||
"}\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()
|
void bitop2()
|
||||||
|
|
|
@ -516,7 +516,7 @@ private:
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\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
|
// this test has an assignment test but doesn't need it
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -571,7 +571,7 @@ private:
|
||||||
" s = strdup(a.s);\n"
|
" s = strdup(a.s);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"}\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
|
// ticket #1224
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -658,7 +658,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" };\n"
|
" };\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
|
// this test has an assignment test but doesn't need it
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -729,7 +729,7 @@ private:
|
||||||
" s = strdup(b.s);\n"
|
" s = strdup(b.s);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\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()
|
void operatorEqToSelf3()
|
||||||
|
@ -1155,7 +1155,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\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(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1172,7 +1172,7 @@ private:
|
||||||
" strcpy(data, a.data);\n"
|
" strcpy(data, a.data);\n"
|
||||||
" return *this;\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(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1188,7 +1188,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\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(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1205,7 +1205,7 @@ private:
|
||||||
" *data = *a.data;\n"
|
" *data = *a.data;\n"
|
||||||
" return *this;\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()
|
void operatorEqToSelf7()
|
||||||
|
@ -1489,7 +1489,7 @@ private:
|
||||||
" ECODES _code;\n"
|
" ECODES _code;\n"
|
||||||
"};\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"
|
checkUninitVar("class A{};\n"
|
||||||
|
@ -1501,7 +1501,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" float f;\n"
|
" float f;\n"
|
||||||
"};\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"
|
checkUninitVar("class C\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1555,7 +1555,7 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
" Bar bars[2];\n"
|
" Bar bars[2];\n"
|
||||||
"};\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.
|
ASSERT_EQUALS("", errout.str()); // So we notice if something is reported.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1636,7 +1636,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"}\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
|
void uninitVar9() // ticket #1730
|
||||||
|
@ -1651,7 +1651,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" SetMinSize( wxSize( 48,48 ) );\n"
|
" SetMinSize( wxSize( 48,48 ) );\n"
|
||||||
"}\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
|
void uninitVar10() // ticket #1993
|
||||||
|
@ -1664,7 +1664,7 @@ private:
|
||||||
" int var2;\n"
|
" int var2;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A() : var1(0) { }\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()
|
void uninitVar11()
|
||||||
|
@ -1676,7 +1676,7 @@ private:
|
||||||
" int var;\n"
|
" int var;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A(int a) { }\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
|
void uninitVar12() // ticket #2078
|
||||||
|
@ -1693,8 +1693,8 @@ private:
|
||||||
" {}\n"
|
" {}\n"
|
||||||
" int x, y;\n"
|
" int x, y;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Point::x'\n"
|
ASSERT_EQUALS("[test.cpp:4]: (warning) 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());
|
"[test.cpp:4]: (warning) Member variable not initialized in the constructor 'Point::y'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarArray1()
|
void uninitVarArray1()
|
||||||
|
@ -1707,7 +1707,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char name[255];\n"
|
" char name[255];\n"
|
||||||
"};\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"
|
checkUninitVar("class John\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1754,7 +1754,7 @@ private:
|
||||||
" John() { }\n"
|
" John() { }\n"
|
||||||
" A *a[5];\n"
|
" A *a[5];\n"
|
||||||
"};\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()
|
void uninitVarArray2()
|
||||||
|
@ -1877,7 +1877,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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
|
// Unknown non-member function
|
||||||
checkUninitVar("class Fred\n"
|
checkUninitVar("class Fred\n"
|
||||||
|
@ -1887,7 +1887,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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
|
// Unknown non-member function
|
||||||
checkUninitVar("class ABC { };\n"
|
checkUninitVar("class ABC { };\n"
|
||||||
|
@ -1898,7 +1898,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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"
|
" unsigned int i;\n"
|
||||||
"};\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()
|
void uninitVarStream()
|
||||||
|
@ -1979,7 +1979,7 @@ private:
|
||||||
" Foo(int _i) { }\n"
|
" Foo(int _i) { }\n"
|
||||||
"};\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"
|
" Fred() { }\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"#endfile\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()
|
void uninitVarHeader3()
|
||||||
|
@ -2044,7 +2044,7 @@ private:
|
||||||
" Fred() { }\n"
|
" Fred() { }\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"#endfile\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
|
// Borland C++: No FP for published pointers - they are automaticly initialized
|
||||||
|
@ -2181,7 +2181,7 @@ private:
|
||||||
" Foo() { }\n"
|
" Foo() { }\n"
|
||||||
"};\n"
|
"};\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"
|
checkUninitVar("namespace n1\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2423,20 +2423,20 @@ private:
|
||||||
void this_subtraction()
|
void this_subtraction()
|
||||||
{
|
{
|
||||||
checkThisSubtraction("; this-x ;");
|
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 ;");
|
checkThisSubtraction("; *this = *this-x ;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkThisSubtraction("; *this = *this-x ;\n"
|
checkThisSubtraction("; *this = *this-x ;\n"
|
||||||
"this-x ;");
|
"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"
|
checkThisSubtraction("; *this = *this-x ;\n"
|
||||||
"this-x ;\n"
|
"this-x ;\n"
|
||||||
"this-x ;\n");
|
"this-x ;\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious pointer subtraction\n"
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction\n"
|
||||||
"[test.cpp:3]: (style) Suspicious pointer subtraction\n", errout.str());
|
"[test.cpp:3]: (warning) Suspicious pointer subtraction\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConst(const char code[], const Settings *s = 0)
|
void checkConst(const char code[], const Settings *s = 0)
|
||||||
|
|
|
@ -136,7 +136,7 @@ private:
|
||||||
" Fred() { }\n"
|
" Fred() { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -157,7 +157,7 @@ private:
|
||||||
" Fred() { }\n"
|
" Fred() { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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"
|
"};\n"
|
||||||
"Fred::Fred()\n"
|
"Fred::Fred()\n"
|
||||||
"{ }\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -218,7 +218,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred()\n"
|
"Fred::Fred()\n"
|
||||||
"{ }\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"
|
"{\n"
|
||||||
" i = _i;\n"
|
" i = _i;\n"
|
||||||
"}\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -251,7 +251,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" i = _i;\n"
|
" i = _i;\n"
|
||||||
"}\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"
|
" void operator=(const Fred &fred) { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -400,7 +400,7 @@ private:
|
||||||
" void operator=(const Fred &fred) { }\n"
|
" void operator=(const Fred &fred) { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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()
|
void initvar_operator_eq3()
|
||||||
|
@ -622,7 +622,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred()\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -649,7 +649,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred()\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() { };\n"
|
||||||
" Fred(const 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"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -701,7 +701,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred() { };\n"
|
"Fred::Fred() { };\n"
|
||||||
"Fred::Fred(const 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
|
void initvar_nested_constructor() // ticket #1375
|
||||||
|
@ -729,10 +729,10 @@ private:
|
||||||
"A::B::B(){}\n"
|
"A::B::B(){}\n"
|
||||||
"A::B::C::C(){}\n"
|
"A::B::C::C(){}\n"
|
||||||
"A::B::C::D::D(){}\n");
|
"A::B::C::D::D(){}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:20]: (style) Member variable not initialized in the constructor 'A::a'\n"
|
ASSERT_EQUALS("[test.cpp:20]: (warning) 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:21]: (warning) 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:22]: (warning) 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());
|
"[test.cpp:23]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str());
|
||||||
|
|
||||||
check("class A {\n"
|
check("class A {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
|
@ -757,10 +757,10 @@ private:
|
||||||
"A::B::B(){}\n"
|
"A::B::B(){}\n"
|
||||||
"A::B::C::C(){}\n"
|
"A::B::C::C(){}\n"
|
||||||
"A::B::C::D::D(const A::B::C::D & d){}\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"
|
ASSERT_EQUALS("[test.cpp:20]: (warning) 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:21]: (warning) 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:22]: (warning) 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());
|
"[test.cpp:23]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str());
|
||||||
|
|
||||||
check("class A {\n"
|
check("class A {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
|
@ -786,10 +786,10 @@ private:
|
||||||
"A::B::B(){}\n"
|
"A::B::B(){}\n"
|
||||||
"A::B::C::C(){}\n"
|
"A::B::C::C(){}\n"
|
||||||
"A::B::C::D::D(const A::B::C::D::E & e){}\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"
|
ASSERT_EQUALS("[test.cpp:21]: (warning) 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:22]: (warning) 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:23]: (warning) 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());
|
"[test.cpp:24]: (warning) Member variable not initialized in the constructor 'D::d'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initvar_destructor()
|
void initvar_destructor()
|
||||||
|
@ -821,7 +821,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"void Fred::operator=(const Fred &f)\n"
|
"void Fred::operator=(const Fred &f)\n"
|
||||||
"{ }", true);
|
"{ }", 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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -378,7 +378,7 @@ private:
|
||||||
// Test the errorlogger..
|
// Test the errorlogger..
|
||||||
ErrorLogger::ErrorMessage errorMessage;
|
ErrorLogger::ErrorMessage errorMessage;
|
||||||
errorMessage._msg = "ab<cd>ef";
|
errorMessage._msg = "ab<cd>ef";
|
||||||
ASSERT_EQUALS("<error id=\"\" severity=\"\" msg=\"ab<cd>ef\"/>", errorMessage.toXML());
|
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab<cd>ef\"/>", errorMessage.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ private:
|
||||||
loc.setfile("ab/cd/../ef.h");
|
loc.setfile("ab/cd/../ef.h");
|
||||||
errorMessage._callStack.push_back(loc);
|
errorMessage._callStack.push_back(loc);
|
||||||
const std::string fname(Path::toNativeSeparators("ab/ef.h"));
|
const std::string fname(Path::toNativeSeparators("ab/ef.h"));
|
||||||
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"\" msg=\"\"/>", errorMessage.toXML());
|
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML());
|
||||||
ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString());
|
ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" throw e;\n"
|
" throw e;\n"
|
||||||
"}\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()
|
void deallocThrow()
|
||||||
|
|
|
@ -89,7 +89,7 @@ private:
|
||||||
" \"abc\";\n"
|
" \"abc\";\n"
|
||||||
"}\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()
|
void test3()
|
||||||
|
@ -124,7 +124,7 @@ private:
|
||||||
" 50;\n"
|
" 50;\n"
|
||||||
"}\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()
|
void test_numeric()
|
||||||
|
|
|
@ -3578,7 +3578,7 @@ private:
|
||||||
" void xy()\n"
|
" void xy()\n"
|
||||||
" { s = malloc(100); }\n"
|
" { s = malloc(100); }\n"
|
||||||
"};\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"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3606,7 +3606,7 @@ private:
|
||||||
" const Fred & operator = (const Fred &f)\n"
|
" const Fred & operator = (const Fred &f)\n"
|
||||||
" { s = malloc(100); }\n"
|
" { s = malloc(100); }\n"
|
||||||
"};\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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2417,19 +2417,19 @@ private:
|
||||||
void passedByValue()
|
void passedByValue()
|
||||||
{
|
{
|
||||||
testPassedByValue("void f(const std::string str) {}");
|
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) {}");
|
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) {}");
|
testPassedByValue("void f(const std::string &str) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
testPassedByValue("void f(const std::vector<int> v) {}");
|
testPassedByValue("void f(const std::vector<int> 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<std::string> v) {}");
|
testPassedByValue("void f(const std::vector<std::string> 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<int> &v) {}");
|
testPassedByValue("void f(const std::vector<int> &v) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -2438,16 +2438,16 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
testPassedByValue("void f(const std::map<int,int> v) {}");
|
testPassedByValue("void f(const std::map<int,int> 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<std::string,std::string> v) {}");
|
testPassedByValue("void f(const std::map<std::string,std::string> 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<int,std::string> v) {}");
|
testPassedByValue("void f(const std::map<int,std::string> 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<std::string,int> v) {}");
|
testPassedByValue("void f(const std::map<std::string,int> 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()
|
void mathfunctionCall1()
|
||||||
|
@ -2633,31 +2633,31 @@ private:
|
||||||
" std::cout << str;\n"
|
" std::cout << str;\n"
|
||||||
" }\n"
|
" }\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)) { }");
|
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) { }");
|
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)) { }");
|
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) { }");
|
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) { }");
|
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)) { }");
|
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)) { }");
|
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)) { }");
|
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()
|
void fflushOnInputStreamTest()
|
||||||
|
@ -2681,13 +2681,13 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int i = sizeof sizeof char;\n"
|
" int i = sizeof sizeof char;\n"
|
||||||
"}\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()
|
void sizeofCalculation()
|
||||||
{
|
{
|
||||||
check("sizeof(a+b)");
|
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)");
|
check("sizeof(-a)");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -2709,7 +2709,7 @@ private:
|
||||||
" y = 3;\n"
|
" y = 3;\n"
|
||||||
" }\n"
|
" }\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2724,7 +2724,7 @@ private:
|
||||||
" y = 3;\n"
|
" y = 3;\n"
|
||||||
" }\n"
|
" }\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2855,21 +2855,21 @@ private:
|
||||||
" x = x;\n"
|
" x = x;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int x = x;\n"
|
" int x = x;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::string var = var = \"test\";\n"
|
" std::string var = var = \"test\";\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2893,8 +2893,8 @@ private:
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) scanf without field width limits can crash with huge input data\n"
|
ASSERT_EQUALS("[test.cpp:6]: (warning) 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());
|
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testScanf2()
|
void testScanf2()
|
||||||
|
@ -2910,8 +2910,8 @@ private:
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) scanf without field width limits can crash with huge input data\n"
|
ASSERT_EQUALS("[test.cpp:6]: (warning) 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());
|
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void trac1132()
|
void trac1132()
|
||||||
|
@ -3097,7 +3097,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
|
@ -3114,7 +3114,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
|
@ -3122,7 +3122,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
|
@ -3130,7 +3130,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
|
@ -3138,7 +3138,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
|
@ -3146,7 +3146,7 @@ private:
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ private:
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -115,7 +115,7 @@ private:
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -131,7 +131,7 @@ private:
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
|
@ -145,7 +145,7 @@ private:
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -198,7 +198,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -222,7 +222,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -263,7 +263,7 @@ private:
|
||||||
" std::cout << k-- << std::endl;\n"
|
" std::cout << k-- << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -310,7 +310,7 @@ private:
|
||||||
" v.clear();\n"
|
" v.clear();\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -327,7 +327,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -343,7 +343,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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"
|
check("\n"
|
||||||
"#include <iostream>\n"
|
"#include <iostream>\n"
|
||||||
|
@ -360,7 +360,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -954,7 +954,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (s.find(12)) { }\n"
|
" if (s.find(12)) { }\n"
|
||||||
"}\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
|
// ok
|
||||||
check("void f(std::set<int> s)\n"
|
check("void f(std::set<int> s)\n"
|
||||||
|
@ -973,7 +973,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (std::find(a,b,c)) { }\n"
|
" if (std::find(a,b,c)) { }\n"
|
||||||
"}\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
|
// ok
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -990,7 +990,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (s.find(\"abc\")) { }\n"
|
" if (s.find(\"abc\")) { }\n"
|
||||||
"}\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<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() == 0) {}\n"
|
" if (x.size() == 0) {}\n"
|
||||||
"}\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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() != 0) {}\n"
|
" if (x.size() != 0) {}\n"
|
||||||
"}\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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() > 0) {}\n"
|
" if (x.size() > 0) {}\n"
|
||||||
"}\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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size()) {}\n"
|
" if (x.size()) {}\n"
|
||||||
"}\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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1063,7 +1063,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\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()
|
void missingInnerComparison2()
|
||||||
|
|
Loading…
Reference in New Issue