Fixed: Ticket #78 Change (always) into (error) in error messages

This commit is contained in:
Reijo Tomperi 2009-02-05 21:06:32 +00:00
parent 09c13d844e
commit a06861948b
9 changed files with 81 additions and 81 deletions

View File

@ -55,7 +55,7 @@ public:
static void outOfBounds(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &what) static void outOfBounds(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &what)
{ {
_writemsg(logger, tokenizer, Location, "always", "" + what + " is out of bounds", "outOfBounds"); _writemsg(logger, tokenizer, Location, "error", "" + what + " is out of bounds", "outOfBounds");
} }
static bool outOfBounds() static bool outOfBounds()
{ {
@ -73,7 +73,7 @@ public:
static void uninitVar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &varname) static void uninitVar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &classname, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Uninitialized member variable '" + classname + "::" + varname + "'", "uninitVar"); _writemsg(logger, tokenizer, Location, "error", "Uninitialized member variable '" + classname + "::" + varname + "'", "uninitVar");
} }
static bool uninitVar() static bool uninitVar()
{ {
@ -91,7 +91,7 @@ public:
static void memsetClass(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc) static void memsetClass(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc)
{ {
_writemsg(logger, tokenizer, Location, "always", "Using '" + memfunc + "' on class", "memsetClass"); _writemsg(logger, tokenizer, Location, "error", "Using '" + memfunc + "' on class", "memsetClass");
} }
static bool memsetClass() static bool memsetClass()
{ {
@ -100,7 +100,7 @@ public:
static void memsetStruct(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc, const std::string &classname) static void memsetStruct(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &memfunc, const std::string &classname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'", "memsetStruct"); _writemsg(logger, tokenizer, Location, "error", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'", "memsetStruct");
} }
static bool memsetStruct() static bool memsetStruct()
{ {
@ -118,7 +118,7 @@ public:
static void virtualDestructor(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &Base, const std::string &Derived) static void virtualDestructor(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &Base, const std::string &Derived)
{ {
_writemsg(logger, tokenizer, Location, "always", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor", "virtualDestructor"); _writemsg(logger, tokenizer, Location, "error", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor", "virtualDestructor");
} }
static bool virtualDestructor() static bool virtualDestructor()
{ {
@ -145,7 +145,7 @@ public:
static void memleak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static void memleak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Memory leak: " + varname + "", "memleak"); _writemsg(logger, tokenizer, Location, "error", "Memory leak: " + varname + "", "memleak");
} }
static bool memleak() static bool memleak()
{ {
@ -163,7 +163,7 @@ public:
static void resourceLeak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static void resourceLeak(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Resource leak: " + varname + "", "resourceLeak"); _writemsg(logger, tokenizer, Location, "error", "Resource leak: " + varname + "", "resourceLeak");
} }
static bool resourceLeak() static bool resourceLeak()
{ {
@ -172,7 +172,7 @@ public:
static void deallocDealloc(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static void deallocDealloc(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Deallocating a deallocated pointer: " + varname + "", "deallocDealloc"); _writemsg(logger, tokenizer, Location, "error", "Deallocating a deallocated pointer: " + varname + "", "deallocDealloc");
} }
static bool deallocDealloc() static bool deallocDealloc()
{ {
@ -181,7 +181,7 @@ public:
static void deallocuse(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static void deallocuse(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Using '" + varname + "' after it is deallocated / released", "deallocuse"); _writemsg(logger, tokenizer, Location, "error", "Using '" + varname + "' after it is deallocated / released", "deallocuse");
} }
static bool deallocuse() static bool deallocuse()
{ {
@ -217,7 +217,7 @@ public:
static void dangerousUsageStrtol(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location) static void dangerousUsageStrtol(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
{ {
_writemsg(logger, tokenizer, Location, "always", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36", "dangerousUsageStrtol"); _writemsg(logger, tokenizer, Location, "error", "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36", "dangerousUsageStrtol");
} }
static bool dangerousUsageStrtol() static bool dangerousUsageStrtol()
{ {
@ -235,7 +235,7 @@ public:
static void sprintfOverlappingData(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname) static void sprintfOverlappingData(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{ {
_writemsg(logger, tokenizer, Location, "always", "Overlapping data buffer " + varname + "", "sprintfOverlappingData"); _writemsg(logger, tokenizer, Location, "error", "Overlapping data buffer " + varname + "", "sprintfOverlappingData");
} }
static bool sprintfOverlappingData() static bool sprintfOverlappingData()
{ {
@ -244,7 +244,7 @@ public:
static void udivError(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location) static void udivError(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
{ {
_writemsg(logger, tokenizer, Location, "always", "Unsigned division. The result will be wrong.", "udivError"); _writemsg(logger, tokenizer, Location, "error", "Unsigned division. The result will be wrong.", "udivError");
} }
static bool udivError() static bool udivError()
{ {
@ -325,7 +325,7 @@ public:
static void strPlusChar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location) static void strPlusChar(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
{ {
_writemsg(logger, tokenizer, Location, "always", "Unusual pointer arithmetic", "strPlusChar"); _writemsg(logger, tokenizer, Location, "error", "Unusual pointer arithmetic", "strPlusChar");
} }
static bool strPlusChar() static bool strPlusChar()
{ {
@ -334,7 +334,7 @@ public:
static void returnLocalVariable(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location) static void returnLocalVariable(ErrorLogger *logger, const Tokenizer *tokenizer, const Token *Location)
{ {
_writemsg(logger, tokenizer, Location, "always", "Returning pointer to local array variable", "returnLocalVariable"); _writemsg(logger, tokenizer, Location, "error", "Returning pointer to local array variable", "returnLocalVariable");
} }
static bool returnLocalVariable() static bool returnLocalVariable()
{ {

View File

@ -417,7 +417,7 @@ private:
" char str[5];\n" " char str[5];\n"
" snprintf(str, 10, \"%s\", \"abc\");\n" " snprintf(str, 10, \"%s\", \"abc\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) snprintf size is out of bounds\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) snprintf size is out of bounds\n"), errout.str());
} }
void snprintf2() void snprintf2()

View File

@ -85,7 +85,7 @@ private:
checkVirtualDestructor("class Base { };\n" checkVirtualDestructor("class Base { };\n"
"class Derived : public Base { public: ~Derived() { (void)11; } };"); "class Derived : public Base { public: ~Derived() { (void)11; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (always) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS(std::string("[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 : Base { public: ~Derived() { (void)11; } };"); "class Derived : Base { public: ~Derived() { (void)11; } };");
@ -98,11 +98,11 @@ private:
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; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (always) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS(std::string("[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; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (always) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS(std::string("[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()
@ -166,7 +166,7 @@ private:
" ECODES _code;\n" " ECODES _code;\n"
"};\n"); "};\n");
ASSERT_EQUALS("[test.cpp:10]: (always) Uninitialized member variable 'Fred::_code'\n", errout.str()); ASSERT_EQUALS("[test.cpp:10]: (error) Uninitialized member variable 'Fred::_code'\n", errout.str());
} }
void uninitVarStream() void uninitVarStream()

View File

@ -97,7 +97,7 @@ private:
" Fred() { }\n" " Fred() { }\n"
" int i;\n" " int i;\n"
"};\n"); "};\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Uninitialized member variable 'Fred::i'\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Uninitialized member variable 'Fred::i'\n"), errout.str());
} }
@ -111,7 +111,7 @@ private:
"};\n" "};\n"
"Fred::Fred()\n" "Fred::Fred()\n"
"{ }\n"); "{ }\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (always) Uninitialized member variable 'Fred::i'\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Uninitialized member variable 'Fred::i'\n"), errout.str());
} }
@ -130,7 +130,7 @@ private:
"{\n" "{\n"
" i = _i;\n" " i = _i;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (always) Uninitialized member variable 'Fred::i'\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Uninitialized member variable 'Fred::i'\n"), errout.str());
} }
@ -197,7 +197,7 @@ private:
" void operator=() { }\n" " void operator=() { }\n"
" int i;\n" " int i;\n"
"};\n"); "};\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Uninitialized member variable 'Fred::i'\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Uninitialized member variable 'Fred::i'\n"), errout.str());
} }
void initvar_operator_eq3() void initvar_operator_eq3()

View File

@ -78,7 +78,7 @@ private:
check(filedata); check(filedata);
// Compare results.. // Compare results..
ASSERT_EQUALS("[file.cpp:5]: (always) Memory leak: string\n", errout.str()); ASSERT_EQUALS("[file.cpp:5]: (error) Memory leak: string\n", errout.str());
} }
}; };

View File

@ -136,7 +136,7 @@ private:
" unsigned int val = 32;\n" " unsigned int val = 32;\n"
" int i = val / -2;\n" " int i = val / -2;\n"
); );
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Unsigned division. The result will be wrong.\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n"), errout.str());
} }
void division7() void division7()
@ -146,7 +146,7 @@ private:
" unsigned int val = 32;\n" " unsigned int val = 32;\n"
" int i = -96 / val;\n" " int i = -96 / val;\n"
); );
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Unsigned division. The result will be wrong.\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n"), errout.str());
} }
}; };

View File

@ -192,7 +192,7 @@ private:
"{\n" "{\n"
" int *a = new int[10];\n" " int *a = new int[10];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Memory leak: a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: a\n"), errout.str());
} }
void simple2() void simple2()
@ -223,7 +223,7 @@ private:
" char *s = new char[100];\n" " char *s = new char[100];\n"
" return 0;\n" " return 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Memory leak: s\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: s\n"), errout.str());
} }
@ -360,7 +360,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: str\n"), errout.str());
} }
@ -386,7 +386,7 @@ private:
" return;\n" " return;\n"
" }\n" " }\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:9]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:9]: (error) Memory leak: str\n"), errout.str());
} }
@ -436,7 +436,7 @@ private:
" }\n" " }\n"
" return NULL;\n" " return NULL;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (always) Memory leak: s\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: s\n"), errout.str());
} }
@ -496,7 +496,7 @@ private:
" return;\n" " return;\n"
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (always) Memory leak: p\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: p\n"), errout.str());
} }
void if2() void if2()
@ -598,7 +598,7 @@ private:
" }\n" " }\n"
" free(c);\n" " free(c);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:11]: (always) Memory leak: c\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: c\n"), errout.str());
} }
void if9() void if9()
@ -642,7 +642,7 @@ private:
" }\n" " }\n"
" delete [] x;\n" " delete [] x;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:6]: (always) Memory leak: x\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: x\n"), errout.str());
} }
@ -680,7 +680,7 @@ private:
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Memory leak: str\n"), errout.str());
} }
@ -695,7 +695,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: str\n"), errout.str());
} }
@ -711,7 +711,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: str\n"), errout.str());
} }
@ -740,7 +740,7 @@ private:
" str = strdup(a[i]);\n" " str = strdup(a[i]);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: str\n"), errout.str());
} }
@ -756,7 +756,7 @@ private:
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Memory leak: str\n"), errout.str());
} }
@ -821,7 +821,7 @@ private:
"\n" "\n"
" return a;\n" " return a;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:11]: (always) Memory leak: a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: a\n"), errout.str());
} }
@ -840,7 +840,7 @@ private:
" while (!str);\n" " while (!str);\n"
" return str;\n" " return str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: str\n"), errout.str());
} }
@ -877,7 +877,7 @@ private:
check(code.c_str(), false); check(code.c_str(), false);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check(code.c_str(), true); check(code.c_str(), true);
ASSERT_EQUALS("[test.cpp:12]: (always) Memory leak: str\n", errout.str()); ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: str\n", errout.str());
} }
void switch3() void switch3()
@ -895,7 +895,7 @@ private:
" }\n" " }\n"
" delete [] str;\n" " delete [] str;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:9]: (always) Memory leak: str\n", errout.str()); ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: str\n", errout.str());
} }
@ -925,7 +925,7 @@ private:
" delete abc;\n" " delete abc;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (always) Memory leak: abc\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: abc\n"), errout.str());
} }
void ret3() void ret3()
@ -935,7 +935,7 @@ private:
" FILE *filep = fopen(\"myfile.txt\",\"w\");\n" " FILE *filep = fopen(\"myfile.txt\",\"w\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Resource leak: filep\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: filep\n"), errout.str());
} }
void ret4() void ret4()
@ -945,7 +945,7 @@ private:
" FILE *p = popen( \"ls -l\", \"r\");\n" " FILE *p = popen( \"ls -l\", \"r\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Resource leak: p\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: p\n"), errout.str());
} }
void ret5() void ret5()
@ -1057,7 +1057,7 @@ private:
" char *p = new char[100];\n" " char *p = new char[100];\n"
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (always) Memory leak: p\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str());
} }
@ -1107,7 +1107,7 @@ private:
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:10]: (always) Memory leak: p\n"), err); ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Memory leak: p\n"), err);
} }
@ -1126,7 +1126,7 @@ private:
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:11]: (always) Memory leak: p\n"), err); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), err);
} }
@ -1372,7 +1372,7 @@ private:
"{\n" "{\n"
" char *str = new char[100];\n" " char *str = new char[100];\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:10]: (always) Memory leak: str\n", errout.str()); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: str\n", errout.str());
} }
void class6() void class6()
@ -1445,7 +1445,7 @@ private:
" delete [] str;\n" " delete [] str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Memory leak: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: str\n"), errout.str());
} }
void throw2() void throw2()
@ -1512,7 +1512,7 @@ private:
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:12]: (always) Memory leak: s2\n"), err); ASSERT_EQUALS(std::string("[test.cpp:12]: (error) Memory leak: s2\n"), err);
} }
@ -1524,7 +1524,7 @@ private:
" a = realloc(a, 100);\n" " a = realloc(a, 100);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Memory leak: a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: a\n"), errout.str());
} }
void realloc2() void realloc2()
@ -1549,7 +1549,7 @@ private:
" free(a);\n" " free(a);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (always) Memory leak: a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Memory leak: a\n"), errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
@ -1618,7 +1618,7 @@ private:
" char *a = reinterpret_cast<char *>(malloc(10));\n" " char *a = reinterpret_cast<char *>(malloc(10));\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Memory leak: a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: a\n"), errout.str());
} }
void cast2() void cast2()
@ -1656,7 +1656,7 @@ private:
" delete abc;\n" " delete abc;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Memory leak: abc.a\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: abc.a\n"), errout.str());
} }
@ -1749,7 +1749,7 @@ private:
" free(str);\n" " free(str);\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (always) Deallocating a deallocated pointer: str\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Deallocating a deallocated pointer: str\n"), errout.str());
} }
void freefree2() void freefree2()

View File

@ -140,7 +140,7 @@ private:
" char buf[100];\n" " char buf[100];\n"
" sprintf(buf,\"%s\",buf);\n" " sprintf(buf,\"%s\",buf);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Overlapping data buffer buf\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Overlapping data buffer buf\n"), errout.str());
} }
void sprintf2() void sprintf2()
@ -207,7 +207,7 @@ private:
"{\n" "{\n"
" const char *p = \"/usr\" + '/';\n" " const char *p = \"/usr\" + '/';\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (always) Unusual pointer arithmetic\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Unusual pointer arithmetic\n"), errout.str());
} }
void strPlusChar2() void strPlusChar2()
@ -218,7 +218,7 @@ private:
" char ch = '/';\n" " char ch = '/';\n"
" const char *p = \"/usr\" + ch;\n" " const char *p = \"/usr\" + ch;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Unusual pointer arithmetic\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unusual pointer arithmetic\n"), errout.str());
} }
void strPlusChar3() void strPlusChar3()
@ -257,7 +257,7 @@ private:
" char str[100] = {0};\n" " char str[100] = {0};\n"
" return str;\n" " return str;\n"
"\n"); "\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (always) Returning pointer to local array variable\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Returning pointer to local array variable\n"), errout.str());
} }
}; };

View File

@ -25,7 +25,7 @@
class Message class Message
{ {
public: public:
enum Settings {always, all, style, style_all, never}; enum Settings {error, all, style, style_all, never};
Message(std::string funcname, Settings settings, std::string msg); Message(std::string funcname, Settings settings, std::string msg);
Message(std::string funcname, Settings settings, std::string msg, std::string par1); Message(std::string funcname, Settings settings, std::string msg, std::string par1);
@ -60,39 +60,39 @@ int main()
// checkbufferoverrun.cpp // checkbufferoverrun.cpp
err.push_back(Message("arrayIndexOutOfBounds", Message::all, "Array index out of bounds")); err.push_back(Message("arrayIndexOutOfBounds", Message::all, "Array index out of bounds"));
err.push_back(Message("bufferOverrun", Message::all, "Buffer overrun")); err.push_back(Message("bufferOverrun", Message::all, "Buffer overrun"));
err.push_back(Message("outOfBounds", Message::always, "%1 is out of bounds", "what")); err.push_back(Message("outOfBounds", Message::error, "%1 is out of bounds", "what"));
// checkclass.cpp.. // checkclass.cpp..
err.push_back(Message("noConstructor", Message::style, "The class '%1' has no constructor", "classname")); err.push_back(Message("noConstructor", Message::style, "The class '%1' has no constructor", "classname"));
err.push_back(Message("uninitVar", Message::always, "Uninitialized member variable '%1::%2'", "classname", "varname")); err.push_back(Message("uninitVar", Message::error, "Uninitialized member variable '%1::%2'", "classname", "varname"));
err.push_back(Message("unusedPrivateFunction", Message::style, "Unused private function '%1::%2'", "classname", "funcname")); err.push_back(Message("unusedPrivateFunction", Message::style, "Unused private function '%1::%2'", "classname", "funcname"));
err.push_back(Message("memsetClass", Message::always, "Using '%1' on class", "memfunc")); err.push_back(Message("memsetClass", Message::error, "Using '%1' on class", "memfunc"));
err.push_back(Message("memsetStruct", Message::always, "Using '%1' on struct that contains a 'std::%2'", "memfunc", "classname")); err.push_back(Message("memsetStruct", Message::error, "Using '%1' on struct that contains a 'std::%2'", "memfunc", "classname"));
err.push_back(Message("operatorEq", Message::style, "'operator=' should return something")); err.push_back(Message("operatorEq", Message::style, "'operator=' should return something"));
err.push_back(Message("virtualDestructor", Message::always, "Class %1 which is inherited by class %2 does not have a virtual destructor", "Base", "Derived")); err.push_back(Message("virtualDestructor", Message::error, "Class %1 which is inherited by class %2 does not have a virtual destructor", "Base", "Derived"));
// checkfunctionusage.cpp.. // checkfunctionusage.cpp..
err.push_back(Message("unusedFunction", Message::style_all, "[%1]: The function '%2' is never used", "filename", "funcname")); err.push_back(Message("unusedFunction", Message::style_all, "[%1]: The function '%2' is never used", "filename", "funcname"));
// checkmemoryleak.cpp.. // checkmemoryleak.cpp..
err.push_back(Message("mismatchAllocDealloc", Message::all, "Mismatching allocation and deallocation: %1", "varname")); err.push_back(Message("mismatchAllocDealloc", Message::all, "Mismatching allocation and deallocation: %1", "varname"));
err.push_back(Message("memleak", Message::always, "Memory leak: %1", "varname")); err.push_back(Message("memleak", Message::error, "Memory leak: %1", "varname"));
err.push_back(Message("memleakall", Message::all, "Memory leak: %1", "varname")); err.push_back(Message("memleakall", Message::all, "Memory leak: %1", "varname"));
err.push_back(Message("resourceLeak", Message::always, "Resource leak: %1", "varname")); err.push_back(Message("resourceLeak", Message::error, "Resource leak: %1", "varname"));
err.push_back(Message("deallocDealloc", Message::always, "Deallocating a deallocated pointer: %1", "varname")); err.push_back(Message("deallocDealloc", Message::error, "Deallocating a deallocated pointer: %1", "varname"));
err.push_back(Message("deallocuse", Message::always, "Using '%1' after it is deallocated / released", "varname")); err.push_back(Message("deallocuse", Message::error, "Using '%1' after it is deallocated / released", "varname"));
// checkother.cpp.. // checkother.cpp..
err.push_back(Message("cstyleCast", Message::style, "C-style pointer casting")); err.push_back(Message("cstyleCast", Message::style, "C-style pointer casting"));
err.push_back(Message("redundantIfDelete0", Message::style, "Redundant condition. It is safe to deallocate a NULL pointer")); err.push_back(Message("redundantIfDelete0", Message::style, "Redundant condition. It is safe to deallocate a NULL pointer"));
err.push_back(Message("redundantIfRemove", Message::style, "Redundant condition. The remove function in the STL will not do anything if element doesn't exist")); err.push_back(Message("redundantIfRemove", Message::style, "Redundant condition. The remove function in the STL will not do anything if element doesn't exist"));
err.push_back(Message("dangerousUsageStrtol", Message::always, "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36")); err.push_back(Message("dangerousUsageStrtol", Message::error, "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36"));
err.push_back(Message("ifNoAction", Message::style, "Found redundant if condition - 'if (condition);'")); err.push_back(Message("ifNoAction", Message::style, "Found redundant if condition - 'if (condition);'"));
err.push_back(Message("sprintfOverlappingData", Message::always, "Overlapping data buffer %1", "varname", "", err.push_back(Message("sprintfOverlappingData", Message::error, "Overlapping data buffer %1", "varname", "",
" -- If copying takes place between objects that overlap as a result of a\n" " -- If copying takes place between objects that overlap as a result of a\n"
" call to sprintf() or snprintf(), the results are undefined.\n" " call to sprintf() or snprintf(), the results are undefined.\n"
" http://www.opengroup.org/onlinepubs/000095399/functions/printf.html")); " http://www.opengroup.org/onlinepubs/000095399/functions/printf.html"));
err.push_back(Message("udivError", Message::always, "Unsigned division. The result will be wrong.")); err.push_back(Message("udivError", Message::error, "Unsigned division. The result will be wrong."));
err.push_back(Message("udivWarning", Message::style_all, "Warning: Division with signed and unsigned operators")); err.push_back(Message("udivWarning", Message::style_all, "Warning: Division with signed and unsigned operators"));
err.push_back(Message("unusedStructMember", Message::style, "struct or union member '%1::%2' is never used", "structname", "varname")); err.push_back(Message("unusedStructMember", Message::style, "struct or union member '%1::%2' is never used", "structname", "varname"));
err.push_back(Message("passedByValue", Message::style, "Function parameter '%1' is passed by value. It could be passed by reference instead.", "parname")); err.push_back(Message("passedByValue", Message::style, "Function parameter '%1' is passed by value. It could be passed by reference instead.", "parname"));
@ -101,8 +101,8 @@ int main()
err.push_back(Message("charBitOp", Message::style, "Warning - using char variable in bit operation")); err.push_back(Message("charBitOp", Message::style, "Warning - using char variable in bit operation"));
err.push_back(Message("variableScope", Message::never, "The scope of the variable %1 can be limited", "varname")); err.push_back(Message("variableScope", Message::never, "The scope of the variable %1 can be limited", "varname"));
err.push_back(Message("conditionAlwaysTrueFalse", Message::style, "Condition is always %1", "truefalse")); err.push_back(Message("conditionAlwaysTrueFalse", Message::style, "Condition is always %1", "truefalse"));
err.push_back(Message("strPlusChar", Message::always, "Unusual pointer arithmetic")); err.push_back(Message("strPlusChar", Message::error, "Unusual pointer arithmetic"));
err.push_back(Message("returnLocalVariable", Message::always, "Returning pointer to local array variable")); err.push_back(Message("returnLocalVariable", Message::error, "Returning pointer to local array variable"));
// Generate code.. // Generate code..
std::cout << "Generate code.." << std::endl; std::cout << "Generate code.." << std::endl;
@ -153,8 +153,8 @@ int main()
std::cout << "Generate doc.." << std::endl; std::cout << "Generate doc.." << std::endl;
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)
{ {
const char *suite[4] = { "always", "all", "style", "all + style" }; const char *suite[4] = { "error", "all", "style", "all + style" };
const Message::Settings settings[4] = { Message::always, Message::all, Message::style, Message::style_all }; const Message::Settings settings[4] = { Message::error, Message::all, Message::style, Message::style_all };
std::cout << " =" << suite[i] << "=" << std::endl; std::cout << " =" << suite[i] << "=" << std::endl;
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it) for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
it->generateDoc(std::cout, settings[i]); it->generateDoc(std::cout, settings[i]);
@ -273,7 +273,7 @@ void Message::generateCode(std::ostream &ostr) const
// Settings.. // Settings..
ostr << " static bool " << _funcname << "("; ostr << " static bool " << _funcname << "(";
if (_settings != always && _settings != never) if (_settings != error && _settings != never)
ostr << "const Settings &s"; ostr << "const Settings &s";
ostr << ")" << std::endl; ostr << ")" << std::endl;
ostr << " {\n"; ostr << " {\n";
@ -294,8 +294,8 @@ std::string Message::stringifySettings(bool text) const
{ {
switch (_settings) switch (_settings)
{ {
case always: case error:
return text ? "always" : "true"; return text ? "error" : "true";
case all: case all:
return text ? "all" : "s._showAll"; return text ? "all" : "s._showAll";
case style: case style: