Message refactorization: checkuninitvar.cpp, checkunusedfunctions.cpp, checkunusedvar.cpp

This commit is contained in:
PKEuS 2012-11-01 18:40:20 +01:00
parent d7b658a5aa
commit 24b98feadb
6 changed files with 186 additions and 186 deletions

View File

@ -1337,12 +1337,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
void CheckUninitVar::uninitstringError(const Token *tok, const std::string &varname, bool strncpy_)
{
reportError(tok, Severity::error, "uninitstring", "Dangerous usage of '" + varname + "'" + (strncpy_ ? " (strncpy doesn't always 0-terminate it)" : " (not 0-terminated)"));
reportError(tok, Severity::error, "uninitstring", "Dangerous usage of '" + varname + "'" + (strncpy_ ? " (strncpy doesn't always 0-terminate it)." : " (not 0-terminated)."));
}
void CheckUninitVar::uninitdataError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::error, "uninitdata", "Data is allocated but not initialized: " + varname);
reportError(tok, Severity::error, "uninitdata", "Memory is allocated but not initialized: " + varname);
}
void CheckUninitVar::uninitvarError(const Token *tok, const std::string &varname)

View File

@ -177,7 +177,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
locationList.push_back(fileLoc);
}
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction", false);
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used.", "unusedFunction", false);
if (errorLogger)
errorLogger->reportErr(errmsg);
else

View File

@ -1026,17 +1026,17 @@ void CheckUnusedVar::unusedVariableError(const Token *tok, const std::string &va
void CheckUnusedVar::allocatedButUnusedVariableError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::style, "unusedAllocatedMemory", "Variable '" + varname + "' is allocated memory that is never used");
reportError(tok, Severity::style, "unusedAllocatedMemory", "Variable '" + varname + "' is allocated memory that is never used.");
}
void CheckUnusedVar::unreadVariableError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::style, "unreadVariable", "Variable '" + varname + "' is assigned a value that is never used");
reportError(tok, Severity::style, "unreadVariable", "Variable '" + varname + "' is assigned a value that is never used.");
}
void CheckUnusedVar::unassignedVariableError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::style, "unassignedVariable", "Variable '" + varname + "' is not assigned a value");
reportError(tok, Severity::style, "unassignedVariable", "Variable '" + varname + "' is not assigned a value.");
}
//---------------------------------------------------------------------------
@ -1129,5 +1129,5 @@ void CheckUnusedVar::checkStructMemberUsage()
void CheckUnusedVar::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
{
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used");
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used.");
}

View File

@ -483,7 +483,7 @@ private:
" char *s = malloc(100);\n"
" *s += 10;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -1257,7 +1257,7 @@ private:
" strcpy(strMsg,buffer);\n"
" free(buffer);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: buffer\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: buffer\n", errout.str());
// #3845
checkUninitVar("int foo() {\n"
@ -1292,42 +1292,42 @@ private:
" char *s = malloc(100);\n"
" strcat(s, \"abc\");\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *s = malloc(100);\n"
" perror(s);\n"
"};");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *s1 = new char[10];\n"
" char *s2 = new char[strlen(s1)];\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s1\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *p = malloc(64);\n"
" int x = p[0];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: p\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *p = malloc(64);\n"
" if (p[0]) { }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: p\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *p = malloc(64);\n"
" return p[0];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: p\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -1407,7 +1407,7 @@ private:
" return;\n"
" char c = *s;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Data is allocated but not initialized: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Memory is allocated but not initialized: s\n", errout.str());
// #3708 - false positive when using ptr typedef
checkUninitVar("void f() {\n"
@ -1572,7 +1572,7 @@ private:
" strncpy(a, s, 20);\n"
" strncat(a, s, 20);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it).\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -1580,7 +1580,7 @@ private:
" strncpy(a, \"hello\", 3);\n"
" strncat(a, \"world\", 20);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it).\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -1623,7 +1623,7 @@ private:
" memset(a, 'a', 20);\n"
" strcat(a, s);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not 0-terminated)\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not 0-terminated).\n", errout.str());
}
std::string analyseFunctions(const char code[]) {

View File

@ -177,19 +177,19 @@ private:
void unusedError() {
check("void foo() {}\n"
"int main()\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
check("void foo() const {}\n"
"int main()\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
check("void foo() const throw() {}\n"
"int main()\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
check("void foo() throw() {}\n"
"int main()\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
}
void unusedMain() {
@ -217,7 +217,7 @@ private:
void returnRef() {
check("int& foo() {return x;}");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
}
void multipleFiles() {
@ -247,15 +247,15 @@ private:
// Check for unused functions..
c.check(this);
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used\n",errout.str());
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
}
void lineNumber() {
check("void foo() {}\n"
"void bar() {}\n"
"int main()\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'bar' is never used\n"
"[test.cpp:1]: (style) The function 'foo' is never used\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'bar' is never used.\n"
"[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
}
};

File diff suppressed because it is too large Load Diff