Message refactorization: checkbufferoverrun.cpp (2), checkclass.cpp, checkexceptionsafety.h
This commit is contained in:
parent
42e68550fc
commit
639f15645a
|
@ -142,7 +142,7 @@ void CheckBufferOverrun::outOfBoundsError(const Token *tok, const std::string &w
|
||||||
void CheckBufferOverrun::pointerOutOfBoundsError(const Token *tok, const std::string &object)
|
void CheckBufferOverrun::pointerOutOfBoundsError(const Token *tok, const std::string &object)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::portability, "pointerOutOfBounds", "Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the " + object + ".\n"
|
reportError(tok, Severity::portability, "pointerOutOfBounds", "Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the " + object + ".\n"
|
||||||
"Undefined behaviour: Using pointer arithmetic so that the result does not point into or just past the end of the " + object + ". Further information: https://www.securecoding.cert.org/confluence/display/seccode/ARR30-C.+Do+not+form+or+use+out+of+bounds+pointers+or+array+subscripts");
|
"Undefined behaviour: The result of this pointer arithmetic does not point into or just one element past the end of the " + object + ". Further information: https://www.securecoding.cert.org/confluence/display/seccode/ARR30-C.+Do+not+form+or+use+out+of+bounds+pointers+or+array+subscripts");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
|
void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
|
||||||
|
@ -156,22 +156,22 @@ void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
|
||||||
void CheckBufferOverrun::terminateStrncpyError(const Token *tok, const std::string &varname)
|
void CheckBufferOverrun::terminateStrncpyError(const Token *tok, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::warning, "terminateStrncpy",
|
reportError(tok, Severity::warning, "terminateStrncpy",
|
||||||
"The buffer '" + varname + "' may not be zero-terminated after the call to strncpy().\n"
|
"The buffer '" + varname + "' may not be null-terminated after the call to strncpy().\n"
|
||||||
"If the source string's size fits or exceeds the given size, strncpy() does not add a "
|
"If the source string's size fits or exceeds the given size, strncpy() does not add a "
|
||||||
"zero at the end of the buffer. This causes bugs later in the code if the code "
|
"zero at the end of the buffer. This causes bugs later in the code if the code "
|
||||||
"assumes buffer is zero-terminated.");
|
"assumes buffer is null-terminated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::cmdLineArgsError(const Token *tok)
|
void CheckBufferOverrun::cmdLineArgsError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "insecureCmdLineArgs", "Buffer overrun possible for long cmd-line args.");
|
reportError(tok, Severity::error, "insecureCmdLineArgs", "Buffer overrun possible for long command line arguments.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBufferOverrun::bufferNotZeroTerminatedError(const Token *tok, const std::string &varname, const std::string &function)
|
void CheckBufferOverrun::bufferNotZeroTerminatedError(const Token *tok, const std::string &varname, const std::string &function)
|
||||||
{
|
{
|
||||||
const std::string errmsg = "The buffer '" + varname + "' is not zero-terminated after the call to " + function + "().\n"
|
const std::string errmsg = "The buffer '" + varname + "' is not null-terminated after the call to " + function + "().\n"
|
||||||
"The buffer '" + varname + "' is not zero-terminated after the call to " + function + "(). "
|
"The buffer '" + varname + "' is not null-terminated after the call to " + function + "(). "
|
||||||
"This will cause bugs later in the code if the code assumes the buffer is zero-terminated.";
|
"This will cause bugs later in the code if the code assumes the buffer is null-terminated.";
|
||||||
|
|
||||||
reportError(tok, Severity::warning, "bufferNotZeroTerminated", errmsg, true);
|
reportError(tok, Severity::warning, "bufferNotZeroTerminated", errmsg, true);
|
||||||
}
|
}
|
||||||
|
@ -2110,7 +2110,8 @@ void CheckBufferOverrun::arrayIndexThenCheckError(const Token *tok, const std::s
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "arrayIndexThenCheck",
|
reportError(tok, Severity::style, "arrayIndexThenCheck",
|
||||||
"Array index '" + indexName + "' is used before limits check.\n"
|
"Array index '" + indexName + "' is used before limits check.\n"
|
||||||
"Defensive programming: The variable '" + indexName + "' is used as array index and then there is a check that it is within limits. This can "
|
"Defensive programming: The variable '" + indexName + "' is used as an array index before it "
|
||||||
"mean that the array might be accessed out of bounds. Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the "
|
"is check that is within limits. This can mean that the array might be accessed out of bounds. "
|
||||||
"array will not be accessed if the index is out of limits.");
|
"Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the array will "
|
||||||
|
"not be accessed if the index is out of limits.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,8 +481,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
|
||||||
"The " + std::string(isStruct ? "struct" : "class") + " '" + classname +
|
"The " + std::string(isStruct ? "struct" : "class") + " '" + classname +
|
||||||
"' does not have a constructor.\n"
|
"' does not have a constructor.\n"
|
||||||
"The " + std::string(isStruct ? "struct" : "class") + " '" + classname +
|
"The " + std::string(isStruct ? "struct" : "class") + " '" + classname +
|
||||||
" 'does not have a constructor but it has attributes. "
|
"' does not have a constructor although it has private member variables. "
|
||||||
"The attributes are not initialized which may cause bugs or undefined behavior.");
|
"Member variables of builtin types are left uninitialized when the class is "
|
||||||
|
"instanciated. That may cause bugs or undefined behavior.");
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -492,7 +493,7 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname,
|
||||||
|
|
||||||
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::warning, "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='.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -657,7 +658,7 @@ void CheckClass::privateFunctions()
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "unusedPrivateFunction", "Unused private function '" + classname + "::" + funcname + "'");
|
reportError(tok, Severity::style, "unusedPrivateFunction", "Unused private function: '" + classname + "::" + funcname + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -749,7 +750,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
||||||
|
|
||||||
void CheckClass::memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type)
|
void CheckClass::memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "memsetClass", "Using '" + memfunc + "' on " + type + " that contains a " + classname);
|
reportError(tok, Severity::error, "memsetClass", "Using '" + memfunc + "' on " + type + " that contains a " + classname + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -790,7 +791,7 @@ void CheckClass::operatorEq()
|
||||||
|
|
||||||
void CheckClass::operatorEqReturnError(const Token *tok, const std::string &className)
|
void CheckClass::operatorEqReturnError(const Token *tok, const std::string &className)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "operatorEq", "\'" + className + "::operator=' should return \'" + className + " &\'");
|
reportError(tok, Severity::style, "operatorEq", "'" + className + "::operator=' should return '" + className + " &'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -880,7 +881,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
|
||||||
|
|
||||||
void CheckClass::operatorEqRetRefThisError(const Token *tok)
|
void CheckClass::operatorEqRetRefThisError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "operatorEqRetRefThis", "'operator=' should return reference to self");
|
reportError(tok, Severity::style, "operatorEqRetRefThis", "'operator=' should return reference to 'this' instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1003,7 +1004,10 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs)
|
||||||
|
|
||||||
void CheckClass::operatorEqToSelfError(const Token *tok)
|
void CheckClass::operatorEqToSelfError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::warning, "operatorEqToSelf", "'operator=' should check for assignment to self");
|
reportError(tok, Severity::warning, "operatorEqToSelf",
|
||||||
|
"'operator=' should check for assignment to self to avoid problems with dynamic memory.\n"
|
||||||
|
"'operator=' should check for assignment to self to ensure that each block of dynamically "
|
||||||
|
"allocated memory is owned and managed by only one instance of the class.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1125,7 +1129,11 @@ void CheckClass::virtualDestructor()
|
||||||
|
|
||||||
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived)
|
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "virtualDestructor", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor");
|
reportError(tok, Severity::error, "virtualDestructor", "Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor.\n"
|
||||||
|
"Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor. "
|
||||||
|
"If you destroy instances of the derived class by deleting a pointer that points to the base class, only "
|
||||||
|
"the destructor of the base class is executed. Thus, dynamic memory that is managed by the derived class "
|
||||||
|
"could leak. This can be avoided by adding a virtual destructor to the base class.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1152,7 +1160,7 @@ void CheckClass::thisSubtraction()
|
||||||
|
|
||||||
void CheckClass::thisSubtractionError(const Token *tok)
|
void CheckClass::thisSubtractionError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::warning, "thisSubtraction", "Suspicious pointer subtraction");
|
reportError(tok, Severity::warning, "thisSubtraction", "Suspicious pointer subtraction. Did you intend to write '->'?");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1540,26 +1548,21 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func)
|
||||||
|
|
||||||
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname)
|
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "functionConst",
|
checkConstError2(tok, 0, classname, funcname);
|
||||||
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
|
||||||
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
|
||||||
"function. Making this function const function should not cause compiler errors. "
|
|
||||||
"Even though the function can be made const function technically it may not make "
|
|
||||||
"sense conceptually. Think about your design and task of the function first - is "
|
|
||||||
"it a function that must not change object internal state?", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
|
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
|
||||||
{
|
{
|
||||||
std::list<const Token *> toks;
|
std::list<const Token *> toks;
|
||||||
toks.push_back(tok1);
|
toks.push_back(tok1);
|
||||||
toks.push_back(tok2);
|
if (tok2)
|
||||||
|
toks.push_back(tok2);
|
||||||
reportError(toks, Severity::style, "functionConst",
|
reportError(toks, Severity::style, "functionConst",
|
||||||
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
"Technically the member function '" + classname + "::" + funcname + "' can be const.\n"
|
||||||
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
"The member function '" + classname + "::" + funcname + "' can be made a const "
|
||||||
"function. Making this function const function should not cause compiler errors. "
|
"function. Making this function 'const' should not cause compiler errors. "
|
||||||
"Even though the function can be made const function technically it may not make "
|
"Even though the function can be made const function technically it may not make "
|
||||||
"sense conceptually. Think about your design and task of the function first - is "
|
"sense conceptually. Think about your design and the task of the function first - is "
|
||||||
"it a function that must not change object internal state?", true);
|
"it a function that must not change object internal state?", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1644,8 +1647,10 @@ void CheckClass::initializerListError(const Token *tok1, const Token *tok2, cons
|
||||||
toks.push_back(tok2);
|
toks.push_back(tok2);
|
||||||
reportError(toks, Severity::style, "initializerList",
|
reportError(toks, Severity::style, "initializerList",
|
||||||
"Member variable '" + classname + "::" +
|
"Member variable '" + classname + "::" +
|
||||||
varname + "' is in the wrong order in the initializer list.\n"
|
varname + "' is in the wrong place in the initializer list.\n"
|
||||||
"Members are initialized in the order they are declared, not the "
|
"Member variable '" + classname + "::" +
|
||||||
|
varname + "' is in the wrong place in the initializer list. "
|
||||||
|
"Members are initialized in the order they are declared, not in the "
|
||||||
"order they are in the initializer list. Keeping the initializer list "
|
"order they are in the initializer list. Keeping the initializer list "
|
||||||
"in the same order that the members were declared prevents order dependent "
|
"in the same order that the members were declared prevents order dependent "
|
||||||
"initialization errors.", true);
|
"initialization errors.", true);
|
||||||
|
|
|
@ -75,24 +75,25 @@ public:
|
||||||
private:
|
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::error, "exceptThrowInDestructor", "Throwing exception in destructor");
|
reportError(tok, Severity::error, "exceptThrowInDestructor", "Exception thrown in destructor.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocThrowError(const Token * const tok, const std::string &varname) {
|
void deallocThrowError(const Token * const tok, const std::string &varname) {
|
||||||
reportError(tok, Severity::warning, "exceptDeallocThrow", "Throwing exception in invalid state, " + varname + " points at deallocated memory");
|
reportError(tok, Severity::warning, "exceptDeallocThrow", "Exception thrown in invalid state, '" +
|
||||||
|
varname + "' points at deallocated memory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrowCopyError(const Token * const tok, const std::string &varname) {
|
void rethrowCopyError(const Token * const tok, const std::string &varname) {
|
||||||
reportError(tok, Severity::style, "exceptRethrowCopy",
|
reportError(tok, Severity::style, "exceptRethrowCopy",
|
||||||
"Throwing a copy of the caught exception instead of rethrowing the original exception\n"
|
"Throwing a copy of the caught exception instead of rethrowing the original exception.\n"
|
||||||
"Rethrowing an exception with 'throw " + varname + ";' makes an unnecessary copy of '" + varname + "'.\n"
|
"Rethrowing an exception with 'throw " + varname + ";' creates an unnecessary copy of '" + varname + "'. "
|
||||||
"To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'.");
|
"To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void catchExceptionByValueError(const Token *tok) {
|
void catchExceptionByValueError(const Token *tok) {
|
||||||
reportError(tok, Severity::style,
|
reportError(tok, Severity::style,
|
||||||
"catchExceptionByValue", "Exception should be caught by reference.\n"
|
"catchExceptionByValue", "Exception should be caught by reference.\n"
|
||||||
"The exception is caught as a value. It could be caught "
|
"The exception is caught by value. It could be caught "
|
||||||
"as a (const) reference which is usually recommended in C++.");
|
"as a (const) reference which is usually recommended in C++.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ private:
|
||||||
"* Throwing exceptions in destructors\n"
|
"* Throwing exceptions in destructors\n"
|
||||||
"* Throwing exception during invalid state\n"
|
"* Throwing exception during invalid state\n"
|
||||||
"* Throwing a copy of a caught exception instead of rethrowing the original exception\n"
|
"* Throwing a copy of a caught exception instead of rethrowing the original exception\n"
|
||||||
"* exception caught by value instead of by reference";
|
"* Exception caught by value instead of by reference";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -1741,7 +1741,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_index_for_continue() {
|
void array_index_for_continue() {
|
||||||
// #3913
|
// #3913
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a[2];\n"
|
" int a[2];\n"
|
||||||
" for (int i = 0; i < 2; ++i) {\n"
|
" for (int i = 0; i < 2; ++i) {\n"
|
||||||
|
@ -3284,7 +3284,7 @@ private:
|
||||||
" char c[6];\n"
|
" char c[6];\n"
|
||||||
" strncpy(c,\"hello!\",sizeof(c));\n"
|
" strncpy(c,\"hello!\",sizeof(c));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to strncpy().\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3323,7 +3323,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]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\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"
|
||||||
|
@ -3338,7 +3338,7 @@ private:
|
||||||
" foo(baz);\n"
|
" foo(baz);\n"
|
||||||
" foo(baz);\n"
|
" foo(baz);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminateStrncpy2() {
|
void terminateStrncpy2() {
|
||||||
|
@ -3349,7 +3349,7 @@ private:
|
||||||
" bar[99] = 0;\n"
|
" bar[99] = 0;\n"
|
||||||
" return baz;\n"
|
" return baz;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminateStrncpy3() {
|
void terminateStrncpy3() {
|
||||||
|
@ -3364,7 +3364,7 @@ private:
|
||||||
"void bar(char *p) {\n"
|
"void bar(char *p) {\n"
|
||||||
" strncpy(p, str, 100);\n"
|
" strncpy(p, str, 100);\n"
|
||||||
"}\n", false);
|
"}\n", false);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'str' may not be zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursive_long_time() {
|
void recursive_long_time() {
|
||||||
|
@ -3532,7 +3532,7 @@ private:
|
||||||
" strcpy(prog, argv[0]);\n"
|
" strcpy(prog, argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char* argv[])\n"
|
check("int main(int argc, char* argv[])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3540,7 +3540,7 @@ private:
|
||||||
" strcat(prog, argv[0]);\n"
|
" strcat(prog, argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char* argv[])\n"
|
check("int main(int argc, char* argv[])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3548,7 +3548,7 @@ private:
|
||||||
" sprintf(prog, \"%s\", argv[0]);\n"
|
" sprintf(prog, \"%s\", argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **argv, char **envp)\n"
|
check("int main(int argc, char **argv, char **envp)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3556,7 +3556,7 @@ private:
|
||||||
" strcpy(prog, argv[0]);\n"
|
" strcpy(prog, argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **argv, char **envp)\n"
|
check("int main(int argc, char **argv, char **envp)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3564,7 +3564,7 @@ private:
|
||||||
" strcat(prog, argv[0]);\n"
|
" strcat(prog, argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **argv, char **envp)\n"
|
check("int main(int argc, char **argv, char **envp)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3572,7 +3572,7 @@ private:
|
||||||
" sprintf(prog, \"%s\", argv[0]);\n"
|
" sprintf(prog, \"%s\", argv[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **options)\n"
|
check("int main(int argc, char **options)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3580,7 +3580,7 @@ private:
|
||||||
" strcpy(prog, options[0]);\n"
|
" strcpy(prog, options[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **options)\n"
|
check("int main(int argc, char **options)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3588,7 +3588,7 @@ private:
|
||||||
" strcat(prog, options[0]);\n"
|
" strcat(prog, options[0]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **options)\n"
|
check("int main(int argc, char **options)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3596,7 +3596,7 @@ private:
|
||||||
" sprintf(prog, \"%s\", *options);\n"
|
" sprintf(prog, \"%s\", *options);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||||
|
|
||||||
check("int main(int argc, char **argv, char **envp)\n"
|
check("int main(int argc, char **argv, char **envp)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3695,21 +3695,21 @@ private:
|
||||||
" char c[6];\n"
|
" char c[6];\n"
|
||||||
" strncpy(c,\"hello!\",sizeof(c));\n"
|
" strncpy(c,\"hello!\",sizeof(c));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to strncpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to strncpy().\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char c[6];\n"
|
" char c[6];\n"
|
||||||
" memcpy(c,\"hello!\",sizeof(c));\n"
|
" memcpy(c,\"hello!\",sizeof(c));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to memcpy().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memcpy().\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char c[6];\n"
|
" char c[6];\n"
|
||||||
" memmove(c,\"hello!\",sizeof(c));\n"
|
" memmove(c,\"hello!\",sizeof(c));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to memmove().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memmove().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void readlink() {
|
void readlink() {
|
||||||
|
@ -3719,7 +3719,7 @@ private:
|
||||||
" ssize_t len = readlink(path, buf, sizeof(buf)-1);\n"
|
" ssize_t len = readlink(path, buf, sizeof(buf)-1);\n"
|
||||||
" printf(\"%s\n\", buf);\n"
|
" printf(\"%s\n\", buf);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlink().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||||
|
|
||||||
// C only: Primitive pointer simplification
|
// C only: Primitive pointer simplification
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -3728,7 +3728,7 @@ private:
|
||||||
" ssize_t len = readlink(path, &buf[0], sizeof(buf)-1);\n"
|
" ssize_t len = readlink(path, &buf[0], sizeof(buf)-1);\n"
|
||||||
" printf(\"%s\n\", buf);\n"
|
" printf(\"%s\n\", buf);\n"
|
||||||
"}\n", true, "test.c");
|
"}\n", true, "test.c");
|
||||||
ASSERT_EQUALS("[test.c:4]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlink().\n", errout.str());
|
ASSERT_EQUALS("[test.c:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3774,7 +3774,7 @@ private:
|
||||||
" ssize_t len = readlinkat(dirfd, path, buf, sizeof(buf)-1);\n"
|
" ssize_t len = readlinkat(dirfd, path, buf, sizeof(buf)-1);\n"
|
||||||
" printf(\"%s\n\", buf);\n"
|
" printf(\"%s\n\", buf);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlinkat().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlinkat().\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -188,7 +188,7 @@ private:
|
||||||
" void goo() {}"
|
" void goo() {}"
|
||||||
" void operator=(const A&);\n"
|
" void operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEq("class A\n"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -222,14 +222,14 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void operator=(const B&);\n"
|
" void operator=(const B&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n"
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n"
|
||||||
"[test.cpp:9]: (style) 'B::operator=' should return 'B &'\n", errout.str());
|
"[test.cpp:9]: (style) 'B::operator=' should return 'B &'.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEq("struct A\n"
|
checkOpertorEq("struct A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" void operator=(const A&);\n"
|
" void operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEq2() {
|
void operatorEq2() {
|
||||||
|
@ -238,28 +238,28 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void * operator=(const A&);\n"
|
" void * operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEq("class A\n"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A * operator=(const A&);\n"
|
" A * operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEq("class A\n"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" const A & operator=(const A&);\n"
|
" const A & operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEq("class A\n"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" B & operator=(const A&);\n"
|
" B & operator=(const A&);\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEq3() { // ticket #3051
|
void operatorEq3() { // ticket #3051
|
||||||
|
@ -321,7 +321,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &a) { return a; }\n"
|
" A & operator=(const A &a) { return a; }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -348,7 +348,7 @@ private:
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return a; }\n");
|
"A & A::operator=(const A &a) { return a; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -357,7 +357,7 @@ private:
|
||||||
" A & operator=(const A &a);\n"
|
" A & operator=(const A &a);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return a; }\n");
|
"A & A::operator=(const A &a) { return a; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -381,7 +381,7 @@ private:
|
||||||
" B & operator=(const B &b) { return b; }\n"
|
" B & operator=(const B &b) { return b; }\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -407,7 +407,7 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { return b; }\n");
|
"A::B & A::B::operator=(const A::B &b) { return b; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqRetRefThis2() {
|
void operatorEqRetRefThis2() {
|
||||||
|
@ -417,7 +417,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" szp &operator =(int *other) {};\n"
|
" szp &operator =(int *other) {};\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class szp\n"
|
"class szp\n"
|
||||||
|
@ -425,7 +425,7 @@ private:
|
||||||
" szp &operator =(int *other);\n"
|
" szp &operator =(int *other);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"szp &szp::operator =(int *other) {}");
|
"szp &szp::operator =(int *other) {}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqRetRefThis3() {
|
void operatorEqRetRefThis3() {
|
||||||
|
@ -494,7 +494,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &a) { }\n"
|
" A & operator=(const A &a) { }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
"class A {\n"
|
"class A {\n"
|
||||||
|
@ -502,7 +502,7 @@ private:
|
||||||
" A & operator=(const A &a);\n"
|
" A & operator=(const A &a);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A :: operator=(const A &a) { }");
|
"A & A :: operator=(const A &a) { }");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)
|
void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault)
|
||||||
|
@ -590,7 +590,7 @@ private:
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\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(
|
||||||
|
@ -645,7 +645,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]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
|
|
||||||
// ticket #1224
|
// ticket #1224
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -731,7 +731,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\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(
|
||||||
|
@ -802,7 +802,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]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqToSelf3() {
|
void operatorEqToSelf3() {
|
||||||
|
@ -1236,7 +1236,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\n"
|
" char * data;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1253,7 +1253,7 @@ private:
|
||||||
" strcpy(data, a.data);\n"
|
" strcpy(data, a.data);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1269,7 +1269,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\n"
|
" char * data;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1286,7 +1286,7 @@ private:
|
||||||
" *data = *a.data;\n"
|
" *data = *a.data;\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqToSelf7() {
|
void operatorEqToSelf7() {
|
||||||
|
@ -1383,13 +1383,13 @@ private:
|
||||||
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualDestructor("class Base { };\n"
|
checkVirtualDestructor("class Base { };\n"
|
||||||
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
|
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualDestructor("class Base { };\n"
|
checkVirtualDestructor("class Base { };\n"
|
||||||
"class Derived : private Base { public: ~Derived() { (void)11; } };"
|
"class Derived : private Base { public: ~Derived() { (void)11; } };"
|
||||||
|
@ -1411,19 +1411,19 @@ private:
|
||||||
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
||||||
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
|
"class Derived : protected Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
||||||
"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };"
|
"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void virtualDestructor4() {
|
void virtualDestructor4() {
|
||||||
|
@ -1466,7 +1466,7 @@ private:
|
||||||
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
"class Derived : public Base { public: ~Derived() { (void)11; } };"
|
||||||
"Base *base = new Derived;\n"
|
"Base *base = new Derived;\n"
|
||||||
"delete base;");
|
"delete base;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
checkVirtualDestructor("class Base { public: ~Base(); };\n"
|
||||||
"class Derived : public Base { public: ~Derived() { (void)11; } };");
|
"class Derived : public Base { public: ~Derived() { (void)11; } };");
|
||||||
|
@ -1580,7 +1580,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" ~B() { int a; }\n"
|
" ~B() { int a; }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class Base which is inherited by class B does not have a virtual destructor\n",
|
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\n",
|
||||||
"", errout.str());
|
"", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1602,7 +1602,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"AA<double> *p = new B; delete p;");
|
"AA<double> *p = new B; delete p;");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Class AA<double> which is inherited by class B does not have a virtual destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) Class 'AA<double>' which is inherited by class 'B' does not have a virtual destructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkNoConstructor(const char code[]) {
|
void checkNoConstructor(const char code[]) {
|
||||||
|
@ -1728,7 +1728,7 @@ private:
|
||||||
" Fred fred;\n"
|
" Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(Fred));\n"
|
" memset(&fred, 0, sizeof(Fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1739,7 +1739,7 @@ private:
|
||||||
" Fred fred;\n"
|
" Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(Fred));\n"
|
" memset(&fred, 0, sizeof(Fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1760,7 +1760,7 @@ private:
|
||||||
" Fred fred;\n"
|
" Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1772,7 +1772,7 @@ private:
|
||||||
" Pebbles pebbles;\n"
|
" Pebbles pebbles;\n"
|
||||||
" memset(&pebbles, 0, sizeof(pebbles));\n"
|
" memset(&pebbles, 0, sizeof(pebbles));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1783,7 +1783,7 @@ private:
|
||||||
" Fred fred;\n"
|
" Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1794,7 +1794,7 @@ private:
|
||||||
" static Fred fred;\n"
|
" static Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class Fred\n"
|
checkNoMemset("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1809,7 +1809,7 @@ private:
|
||||||
" Pebbles pebbles;\n"
|
" Pebbles pebbles;\n"
|
||||||
" memset(&pebbles, 0, sizeof(pebbles));\n"
|
" memset(&pebbles, 0, sizeof(pebbles));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on class that contains a virtual method\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str());
|
||||||
|
|
||||||
// Fred not defined in scope
|
// Fred not defined in scope
|
||||||
checkNoMemset("namespace n1 {\n"
|
checkNoMemset("namespace n1 {\n"
|
||||||
|
@ -1837,7 +1837,7 @@ private:
|
||||||
" n1::Fred fred;\n"
|
" n1::Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(n1::Fred));\n"
|
" memset(&fred, 0, sizeof(n1::Fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
// Fred with namespace qualifier
|
// Fred with namespace qualifier
|
||||||
checkNoMemset("namespace n1 {\n"
|
checkNoMemset("namespace n1 {\n"
|
||||||
|
@ -1851,7 +1851,7 @@ private:
|
||||||
" n1::Fred fred;\n"
|
" n1::Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void memsetOnStruct() {
|
void memsetOnStruct() {
|
||||||
|
@ -1903,7 +1903,7 @@ private:
|
||||||
" struct A fail;\n"
|
" struct A fail;\n"
|
||||||
" memset(&fail, 0, sizeof(struct A));\n"
|
" memset(&fail, 0, sizeof(struct A));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct Fred\n"
|
checkNoMemset("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1914,7 +1914,7 @@ private:
|
||||||
" Fred fred;\n"
|
" Fred fred;\n"
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct Stringy {\n"
|
checkNoMemset("struct Stringy {\n"
|
||||||
" std::string inner;\n"
|
" std::string inner;\n"
|
||||||
|
@ -1927,7 +1927,7 @@ private:
|
||||||
" memset(&foo, 0, sizeof(Foo));\n"
|
" memset(&foo, 0, sizeof(Foo));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void memsetVector() {
|
void memsetVector() {
|
||||||
|
@ -1939,7 +1939,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector<int> ints; };\n"
|
"{ std::vector<int> ints; };\n"
|
||||||
|
@ -1949,7 +1949,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector<int> ints; };\n"
|
"{ std::vector<int> ints; };\n"
|
||||||
|
@ -1959,7 +1959,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(struct A));\n"
|
" memset(&a, 0, sizeof(struct A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector<int> ints; };\n"
|
"{ std::vector<int> ints; };\n"
|
||||||
|
@ -1969,7 +1969,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(a));\n"
|
" memset(&a, 0, sizeof(a));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("class A\n"
|
checkNoMemset("class A\n"
|
||||||
"{ std::vector< std::vector<int> > ints; };\n"
|
"{ std::vector< std::vector<int> > ints; };\n"
|
||||||
|
@ -1979,7 +1979,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector< std::vector<int> > ints; };\n"
|
"{ std::vector< std::vector<int> > ints; };\n"
|
||||||
|
@ -1989,7 +1989,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector< std::vector<int> > ints; };\n"
|
"{ std::vector< std::vector<int> > ints; };\n"
|
||||||
|
@ -1999,7 +1999,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(a));\n"
|
" memset(&a, 0, sizeof(a));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A\n"
|
checkNoMemset("struct A\n"
|
||||||
"{ std::vector<int *> ints; };\n"
|
"{ std::vector<int *> ints; };\n"
|
||||||
|
@ -2009,7 +2009,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2033,20 +2033,20 @@ private:
|
||||||
|
|
||||||
void this_subtraction() {
|
void this_subtraction() {
|
||||||
checkThisSubtraction("; this-x ;");
|
checkThisSubtraction("; this-x ;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\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]: (warning) Suspicious pointer subtraction\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\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]: (warning) Suspicious pointer subtraction\n"
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n"
|
||||||
"[test.cpp:3]: (warning) Suspicious pointer subtraction\n", errout.str());
|
"[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true) {
|
void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true) {
|
||||||
|
@ -5099,8 +5099,8 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" Fred() : c(0), b(0), a(0) { }\n"
|
" Fred() : c(0), b(0), a(0) { }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong order in the initializer list.\n"
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list.\n"
|
||||||
"[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong order in the initializer list.\n", errout.str());
|
"[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkInitializationListUsage(const char code[]) {
|
void checkInitializationListUsage(const char code[]) {
|
||||||
|
|
|
@ -343,7 +343,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]: (warning) 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() {
|
||||||
|
@ -372,7 +372,7 @@ private:
|
||||||
" return *this\n"
|
" return *this\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -387,7 +387,7 @@ private:
|
||||||
" return *this\n"
|
" return *this\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -402,7 +402,7 @@ private:
|
||||||
" return *this\n"
|
" return *this\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -812,7 +812,7 @@ private:
|
||||||
" const A& operator=(const A&){return *this;}\n"
|
" const A& operator=(const A&){return *this;}\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
||||||
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str());
|
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str());
|
||||||
|
|
||||||
check("class A\n"
|
check("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -823,7 +823,7 @@ private:
|
||||||
" const A& operator=(const A&){return *this;}\n"
|
" const A& operator=(const A&){return *this;}\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
||||||
"[test.cpp:7]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str());
|
"[test.cpp:7]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initvar_nocopy2() { // ticket #2484
|
void initvar_nocopy2() { // ticket #2484
|
||||||
|
@ -857,7 +857,7 @@ private:
|
||||||
" const A& operator=(const A&){return *this;}\n"
|
" const A& operator=(const A&){return *this;}\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n"
|
||||||
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str());
|
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initvar_destructor() {
|
void initvar_destructor() {
|
||||||
|
@ -887,7 +887,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]: (warning) 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVar1() {
|
void uninitVar1() {
|
||||||
|
@ -1045,7 +1045,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (warning) 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
|
||||||
|
@ -1504,7 +1504,7 @@ private:
|
||||||
"Fred & Fred::clone(const Fred & other) {\n"
|
"Fred & Fred::clone(const Fred & other) {\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarArray1() {
|
void uninitVarArray1() {
|
||||||
|
@ -2325,7 +2325,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
||||||
"[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='\n", errout.str());
|
"[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarPointer() { // #3801
|
void uninitVarPointer() { // #3801
|
||||||
|
@ -2375,7 +2375,7 @@ private:
|
||||||
" A* const a;\n"
|
" A* const a;\n"
|
||||||
" B& operator=(const B& r) { }\n"
|
" B& operator=(const B& r) { }\n"
|
||||||
"};");
|
"};");
|
||||||
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (warning) Member variable 'B::a' is not assigned a value in 'B::operator='\n", errout.str()); // #3804
|
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (warning) Member variable 'B::a' is not assigned a value in 'B::operator='.\n", errout.str()); // #3804
|
||||||
|
|
||||||
check("struct B {\n"
|
check("struct B {\n"
|
||||||
" const int a;\n"
|
" const int a;\n"
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
" throw e;\n"
|
" throw e;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Exception thrown in destructor.\n", errout.str());
|
||||||
|
|
||||||
check("class x {\n"
|
check("class x {\n"
|
||||||
" ~x();\n"
|
" ~x();\n"
|
||||||
|
@ -76,14 +76,14 @@ private:
|
||||||
"x::~x() {\n"
|
"x::~x() {\n"
|
||||||
" throw e;\n"
|
" throw e;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Throwing exception in destructor\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Exception thrown in destructor.\n", errout.str());
|
||||||
|
|
||||||
check("x::~x() {\n"
|
check("x::~x() {\n"
|
||||||
" throw e;\n"
|
" throw e;\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Exception thrown in destructor.\n", "", errout.str());
|
||||||
|
|
||||||
// #3858 - throwing exception in try block in destructor
|
// #3858 - throwing exception in try block in destructor.
|
||||||
check("class x {\n"
|
check("class x {\n"
|
||||||
" ~x() {\n"
|
" ~x() {\n"
|
||||||
" try {\n"
|
" try {\n"
|
||||||
|
@ -103,7 +103,7 @@ private:
|
||||||
" throw 123;\n"
|
" throw 123;\n"
|
||||||
" p = 0;\n"
|
" p = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" static int* p = foo;\n"
|
" static int* p = foo;\n"
|
||||||
|
@ -112,7 +112,7 @@ private:
|
||||||
" throw 1;\n"
|
" throw 1;\n"
|
||||||
" p = 0;\n"
|
" p = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocThrow2() {
|
void deallocThrow2() {
|
||||||
|
@ -147,7 +147,7 @@ private:
|
||||||
" delete p;\n"
|
" delete p;\n"
|
||||||
" throw 1;\n"
|
" throw 1;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrowCopy1() {
|
void rethrowCopy1() {
|
||||||
|
@ -161,7 +161,7 @@ private:
|
||||||
" throw err;\n"
|
" throw err;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrowCopy2() {
|
void rethrowCopy2() {
|
||||||
|
@ -175,7 +175,7 @@ private:
|
||||||
" throw err;\n"
|
" throw err;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrowCopy3() {
|
void rethrowCopy3() {
|
||||||
|
@ -187,7 +187,7 @@ private:
|
||||||
" throw err;\n"
|
" throw err;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rethrowCopy4() {
|
void rethrowCopy4() {
|
||||||
|
@ -219,7 +219,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" try {\n"
|
" try {\n"
|
||||||
|
|
Loading…
Reference in New Issue