Merge branch 'master' of github.com:danmar/cppcheck

This commit is contained in:
Edoardo Prezioso 2011-10-05 19:52:49 +02:00
commit d741f64256
10 changed files with 169 additions and 165 deletions

View File

@ -219,7 +219,11 @@ void MainWindow::LoadSettings()
mUI.mActionShowInformation->setChecked(mSettings->value(SETTINGS_SHOW_INFORMATION, true).toBool()); mUI.mActionShowInformation->setChecked(mSettings->value(SETTINGS_SHOW_INFORMATION, true).toBool());
mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked()); mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
mUI.mResults->ShowResults(SHOW_WARNINGS, mUI.mActionShowWarnings->isChecked());
mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked()); mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked());
mUI.mResults->ShowResults(SHOW_PORTABILITY, mUI.mActionShowPortability->isChecked());
mUI.mResults->ShowResults(SHOW_PERFORMANCE, mUI.mActionShowPerformance->isChecked());
mUI.mResults->ShowResults(SHOW_INFORMATION, mUI.mActionShowInformation->isChecked());
// Main window settings // Main window settings
const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool(); const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool();

View File

@ -34,7 +34,7 @@ void Platforms::add(const QString &title, Settings::PlatformType platform)
void Platforms::init() void Platforms::init()
{ {
add(tr("Default"), Settings::Unspecified); add(tr("Build-in"), Settings::Unspecified);
add(tr("Unix 32-bit"), Settings::Unix32); add(tr("Unix 32-bit"), Settings::Unix32);
add(tr("Unix 64-bit"), Settings::Unix64); add(tr("Unix 64-bit"), Settings::Unix64);
add(tr("Windows 32-bit ANSI"), Settings::Win32A); add(tr("Windows 32-bit ANSI"), Settings::Win32A);

View File

@ -191,5 +191,5 @@ void CheckAssignIf::multiConditionError(const Token *tok, unsigned int line1)
errmsg << "'else if' condition matches previous condition at line " errmsg << "'else if' condition matches previous condition at line "
<< line1; << line1;
reportError(tok, Severity::information, "multiCondition", errmsg.str()); reportError(tok, Severity::style, "multiCondition", errmsg.str());
} }

View File

@ -1762,7 +1762,7 @@ bool CheckClass::isVirtualFunc(const Scope *scope, const Token *functionToken) c
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::information, "functionConst", reportError(tok, 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 function should not cause compiler errors. "
@ -1776,7 +1776,7 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
std::list<const Token *> toks; std::list<const Token *> toks;
toks.push_back(tok1); toks.push_back(tok1);
toks.push_back(tok2); toks.push_back(tok2);
reportError(toks, Severity::information, "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 function should not cause compiler errors. "

View File

@ -60,7 +60,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
{ {
// If checking an old code base it might be uninteresting to update obsolete functions. // If checking an old code base it might be uninteresting to update obsolete functions.
// Therefore this is "information" // Therefore this is "information"
reportError(tok->tokAt(1), Severity::information, "obsoleteFunctions"+it->first, it->second); reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
break; break;
} }
else if (_settings->posix) else if (_settings->posix)
@ -70,7 +70,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
{ {
// If checking an old code base it might be uninteresting to update obsolete functions. // If checking an old code base it might be uninteresting to update obsolete functions.
// Therefore this is "information" // Therefore this is "information"
reportError(tok->tokAt(1), Severity::information, "obsoleteFunctions"+it->first, it->second); reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
break; break;
} }
} }

View File

@ -1558,7 +1558,7 @@ void CheckOther::lookupVar(const Token *tok1, const std::string &varname)
void CheckOther::variableScopeError(const Token *tok, const std::string &varname) void CheckOther::variableScopeError(const Token *tok, const std::string &varname)
{ {
reportError(tok, reportError(tok,
Severity::information, Severity::style,
"variableScope", "variableScope",
"The scope of the variable '" + varname + "' can be reduced\n" "The scope of the variable '" + varname + "' can be reduced\n"
"The scope of the variable '" + varname + "' can be reduced. Warning: It can be unsafe " "The scope of the variable '" + varname + "' can be reduced. Warning: It can be unsafe "

View File

@ -121,14 +121,14 @@ private:
" if (x & 7);\n" " if (x & 7);\n"
" else if (x == 1);\n" " else if (x == 1);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (information) 'else if' condition matches previous condition at line 3\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) 'else if' condition matches previous condition at line 3\n", errout.str());
check("void foo(int x)\n" check("void foo(int x)\n"
"{\n" "{\n"
" if (x & 7);\n" " if (x & 7);\n"
" else if (x & 1);\n" " else if (x & 1);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (information) 'else if' condition matches previous condition at line 3\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) 'else if' condition matches previous condition at line 3\n", errout.str());
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,7 @@ private:
"{\n" "{\n"
" bsd_signal(SIGABRT, SIG_IGN);\n" " bsd_signal(SIGABRT, SIG_IGN);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (information) Found obsolete function 'bsd_signal'. It is recommended that new applications use the 'sigaction' function\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Found obsolete function 'bsd_signal'. It is recommended that new applications use the 'sigaction' function\n", errout.str());
check("int f()\n" check("int f()\n"
"{\n" "{\n"
@ -105,7 +105,7 @@ private:
" exit(1);\n" " exit(1);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (information) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function\n", errout.str());
} }
void testgethostbyaddr() void testgethostbyaddr()
@ -118,7 +118,7 @@ private:
" exit(1);\n" " exit(1);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (information) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getnameinfo' function\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (style) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getnameinfo' function\n", errout.str());
} }
void testusleep() void testusleep()
@ -127,7 +127,7 @@ private:
"{\n" "{\n"
" usleep( 1000 );\n" " usleep( 1000 );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (information) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function\n", errout.str());
} }
void testindex() void testindex()
@ -168,7 +168,7 @@ private:
" const char i = index(var, 0);\n" " const char i = index(var, 0);\n"
" return i;\n" " return i;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (information) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n",
errout.str()); errout.str());
} }
@ -177,7 +177,7 @@ private:
check("void TDataModel::forceRowRefresh(int row) {\n" check("void TDataModel::forceRowRefresh(int row) {\n"
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (information) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", errout.str());
} }
void testrindex() void testrindex()
@ -193,7 +193,7 @@ private:
" const char var[7] = 'rindex';\n" " const char var[7] = 'rindex';\n"
" print(rindex(var, 0));\n" " print(rindex(var, 0));\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (information) Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead\n", errout.str());
} }
@ -213,7 +213,7 @@ private:
"{\n" "{\n"
" char *x = gets();\n" " char *x = gets();\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (information) Found obsolete function 'gets'. It is recommended to use the function 'fgets' instead\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Found obsolete function 'gets'. It is recommended to use the function 'fgets' instead\n", errout.str());
} }
// ticket #3121 // ticket #3121

View File

@ -604,7 +604,7 @@ private:
" for ( ; i < 10; ++i) ;\n" " for ( ; i < 10; ++i) ;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (information) The scope of the variable 'i' can be reduced\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced\n", errout.str());
varScope("void f(int x)\n" varScope("void f(int x)\n"
"{\n" "{\n"
@ -614,7 +614,7 @@ private:
" for ( ; i < 10; ++i) ;\n" " for ( ; i < 10; ++i) ;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (information) The scope of the variable 'i' can be reduced\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced\n", errout.str());
} }
void varScope6() void varScope6()
@ -680,7 +680,7 @@ private:
" edgeResistance = (edge+1) / 2.0;\n" " edgeResistance = (edge+1) / 2.0;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (information) The scope of the variable 'edgeResistance' can be reduced\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'edgeResistance' can be reduced\n", errout.str());
} }
void varScope9() void varScope9()