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)
{
_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()
{
@ -73,7 +73,7 @@ public:
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()
{
@ -91,7 +91,7 @@ public:
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()
{
@ -100,7 +100,7 @@ public:
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()
{
@ -118,7 +118,7 @@ public:
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()
{
@ -145,7 +145,7 @@ public:
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()
{
@ -163,7 +163,7 @@ public:
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()
{
@ -172,7 +172,7 @@ public:
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()
{
@ -181,7 +181,7 @@ public:
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()
{
@ -217,7 +217,7 @@ public:
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()
{
@ -235,7 +235,7 @@ public:
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()
{
@ -244,7 +244,7 @@ public:
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()
{
@ -325,7 +325,7 @@ public:
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()
{
@ -334,7 +334,7 @@ public:
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()
{

View File

@ -417,7 +417,7 @@ private:
" char str[5];\n"
" snprintf(str, 10, \"%s\", \"abc\");\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()

View File

@ -85,7 +85,7 @@ private:
checkVirtualDestructor("class Base { };\n"
"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"
"class Derived : Base { public: ~Derived() { (void)11; } };");
@ -98,11 +98,11 @@ private:
checkVirtualDestructor("class Base { public: ~Base(); };\n"
"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"
"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()
@ -166,7 +166,7 @@ private:
" ECODES _code;\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()

View File

@ -97,7 +97,7 @@ private:
" Fred() { }\n"
" int i;\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"
"Fred::Fred()\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"
" i = _i;\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"
" int i;\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()

View File

@ -78,7 +78,7 @@ private:
check(filedata);
// 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"
" 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()
@ -146,7 +146,7 @@ private:
" unsigned int val = 32;\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"
" int *a = new int[10];\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()
@ -223,7 +223,7 @@ private:
" char *s = new char[100];\n"
" return 0;\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"
" free(str);\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"
" }\n"
"}\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"
" return NULL;\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"
" foo(p);\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()
@ -598,7 +598,7 @@ private:
" }\n"
" free(c);\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()
@ -642,7 +642,7 @@ private:
" }\n"
" delete [] x;\n"
"}\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"
" }\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"
" free(str);\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"
" free(str);\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"
" }\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"
" }\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"
" return a;\n"
"}\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"
" return str;\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);
ASSERT_EQUALS("", errout.str());
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()
@ -895,7 +895,7 @@ private:
" }\n"
" delete [] str;\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"
"}\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()
@ -935,7 +935,7 @@ private:
" FILE *filep = fopen(\"myfile.txt\",\"w\");\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()
@ -945,7 +945,7 @@ private:
" FILE *p = popen( \"ls -l\", \"r\");\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()
@ -1057,7 +1057,7 @@ private:
" char *p = new char[100];\n"
" foo(p);\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"
"}\n");
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"
"}\n");
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"
" char *str = new char[100];\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()
@ -1445,7 +1445,7 @@ private:
" delete [] str;\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()
@ -1512,7 +1512,7 @@ private:
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"
"}\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()
@ -1549,7 +1549,7 @@ private:
" free(a);\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"
"{\n"
@ -1618,7 +1618,7 @@ private:
" char *a = reinterpret_cast<char *>(malloc(10));\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()
@ -1656,7 +1656,7 @@ private:
" delete abc;\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"
"}\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()

View File

@ -140,7 +140,7 @@ private:
" char buf[100];\n"
" sprintf(buf,\"%s\",buf);\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()
@ -207,7 +207,7 @@ private:
"{\n"
" const char *p = \"/usr\" + '/';\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()
@ -218,7 +218,7 @@ private:
" char ch = '/';\n"
" const char *p = \"/usr\" + ch;\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()
@ -257,7 +257,7 @@ private:
" char str[100] = {0};\n"
" return str;\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
{
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, std::string par1);
@ -60,39 +60,39 @@ int main()
// checkbufferoverrun.cpp
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("outOfBounds", Message::always, "%1 is out of bounds", "what"));
err.push_back(Message("outOfBounds", Message::error, "%1 is out of bounds", "what"));
// checkclass.cpp..
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("memsetClass", Message::always, "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("memsetClass", Message::error, "Using '%1' on class", "memfunc"));
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("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..
err.push_back(Message("unusedFunction", Message::style_all, "[%1]: The function '%2' is never used", "filename", "funcname"));
// checkmemoryleak.cpp..
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("resourceLeak", Message::always, "Resource leak: %1", "varname"));
err.push_back(Message("deallocDealloc", Message::always, "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("resourceLeak", Message::error, "Resource leak: %1", "varname"));
err.push_back(Message("deallocDealloc", Message::error, "Deallocating a deallocated pointer: %1", "varname"));
err.push_back(Message("deallocuse", Message::error, "Using '%1' after it is deallocated / released", "varname"));
// checkother.cpp..
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("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("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"
" call to sprintf() or snprintf(), the results are undefined.\n"
" 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("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"));
@ -101,8 +101,8 @@ int main()
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("conditionAlwaysTrueFalse", Message::style, "Condition is always %1", "truefalse"));
err.push_back(Message("strPlusChar", Message::always, "Unusual pointer arithmetic"));
err.push_back(Message("returnLocalVariable", Message::always, "Returning pointer to local array variable"));
err.push_back(Message("strPlusChar", Message::error, "Unusual pointer arithmetic"));
err.push_back(Message("returnLocalVariable", Message::error, "Returning pointer to local array variable"));
// Generate code..
std::cout << "Generate code.." << std::endl;
@ -153,8 +153,8 @@ int main()
std::cout << "Generate doc.." << std::endl;
for (unsigned int i = 0; i < 4; ++i)
{
const char *suite[4] = { "always", "all", "style", "all + style" };
const Message::Settings settings[4] = { Message::always, Message::all, Message::style, Message::style_all };
const char *suite[4] = { "error", "all", "style", "all + style" };
const Message::Settings settings[4] = { Message::error, Message::all, Message::style, Message::style_all };
std::cout << " =" << suite[i] << "=" << std::endl;
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
it->generateDoc(std::cout, settings[i]);
@ -273,7 +273,7 @@ void Message::generateCode(std::ostream &ostr) const
// Settings..
ostr << " static bool " << _funcname << "(";
if (_settings != always && _settings != never)
if (_settings != error && _settings != never)
ostr << "const Settings &s";
ostr << ")" << std::endl;
ostr << " {\n";
@ -294,8 +294,8 @@ std::string Message::stringifySettings(bool text) const
{
switch (_settings)
{
case always:
return text ? "always" : "true";
case error:
return text ? "error" : "true";
case all:
return text ? "all" : "s._showAll";
case style: