Uninitvar: Reactivated the checking
This commit is contained in:
parent
ca9dbfc031
commit
414e0ecc3c
|
@ -27,8 +27,7 @@
|
||||||
|
|
||||||
// Register this check class (by creating a static instance of it)
|
// Register this check class (by creating a static instance of it)
|
||||||
namespace {
|
namespace {
|
||||||
// The ExecutionPath framework doesn't work as well as I wanted
|
CheckUninitVar instance;
|
||||||
//CheckUninitVar instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -1019,9 +1018,6 @@ void CheckUninitVar::saveAnalysisData(const std::set<std::string> &data) const
|
||||||
|
|
||||||
void CheckUninitVar::executionPaths()
|
void CheckUninitVar::executionPaths()
|
||||||
{
|
{
|
||||||
if (!_settings->experimental)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// check if variable is accessed uninitialized..
|
// check if variable is accessed uninitialized..
|
||||||
{
|
{
|
||||||
// no writing if multiple threads are used (TODO: thread safe analysis?)
|
// no writing if multiple threads are used (TODO: thread safe analysis?)
|
||||||
|
|
|
@ -157,7 +157,6 @@ private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._inlineSuppressions = true;
|
settings._inlineSuppressions = true;
|
||||||
settings.experimental = true;
|
|
||||||
if (!suppression.empty())
|
if (!suppression.empty())
|
||||||
settings.nomsg.addSuppressionLine(suppression);
|
settings.nomsg.addSuppressionLine(suppression);
|
||||||
|
|
||||||
|
@ -172,16 +171,18 @@ private:
|
||||||
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) {
|
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) {
|
||||||
// check to make sure the appropriate error is present
|
// check to make sure the appropriate error is present
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a = 4 / 0;\n"
|
" int a;\n"
|
||||||
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar globally
|
// suppress uninitvar globally
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a = 4 / 0;\n"
|
" int a;\n"
|
||||||
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv");
|
"uninitvar");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar globally, without error present
|
// suppress uninitvar globally, without error present
|
||||||
|
@ -189,15 +190,15 @@ private:
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" b++;\n"
|
" b++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv");
|
"uninitvar");
|
||||||
ASSERT_EQUALS("[*]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
ASSERT_EQUALS("[*]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar for this file only
|
// suppress uninitvar for this file only
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a = 4 / 0;\n"
|
" int a;\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv:test.cpp");
|
"uninitvar:test.cpp");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar for this file only, without error present
|
// suppress uninitvar for this file only, without error present
|
||||||
|
@ -205,13 +206,13 @@ private:
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" b++;\n"
|
" b++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv:test.cpp");
|
"uninitvar:test.cpp");
|
||||||
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||||
|
|
||||||
// suppress all for this file only
|
// suppress all for this file only
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"*:test.cpp");
|
"*:test.cpp");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -227,24 +228,24 @@ private:
|
||||||
// suppress uninitvar for this file and line
|
// suppress uninitvar for this file and line
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv:test.cpp:3");
|
"uninitvar:test.cpp:3");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar for this file and line, without error present
|
// suppress uninitvar for this file and line, without error present
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" a = 4;\n"
|
" b++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"zerodiv:test.cpp:3");
|
"uninitvar:test.cpp:3");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||||
|
|
||||||
// suppress uninitvar inline
|
// suppress uninitvar inline
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" // cppcheck-suppress zerodiv\n"
|
" // cppcheck-suppress uninitvar\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -252,9 +253,9 @@ private:
|
||||||
// suppress uninitvar inline
|
// suppress uninitvar inline
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" // cppcheck-suppress zerodiv\n"
|
" // cppcheck-suppress uninitvar\n"
|
||||||
"\n"
|
"\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -262,8 +263,8 @@ private:
|
||||||
// suppress uninitvar inline
|
// suppress uninitvar inline
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" /* cppcheck-suppress zerodiv */\n"
|
" /* cppcheck-suppress uninitvar */\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -271,9 +272,9 @@ private:
|
||||||
// suppress uninitvar inline
|
// suppress uninitvar inline
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" /* cppcheck-suppress zerodiv */\n"
|
" /* cppcheck-suppress uninitvar */\n"
|
||||||
"\n"
|
"\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -281,11 +282,11 @@ private:
|
||||||
// suppress uninitvar inline, without error present
|
// suppress uninitvar inline, without error present
|
||||||
(this->*check)("void f() {\n"
|
(this->*check)("void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" // cppcheck-suppress zerodiv\n"
|
" // cppcheck-suppress uninitvar\n"
|
||||||
" a = 4;\n"
|
" b++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"");
|
"");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void suppressionsSettings() {
|
void suppressionsSettings() {
|
||||||
|
@ -301,12 +302,12 @@ private:
|
||||||
"}\n",
|
"}\n",
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" a = 4 / 0;\n"
|
" a++;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
};
|
};
|
||||||
|
|
||||||
// suppress uninitvar for this file and line
|
// suppress uninitvar for this file and line
|
||||||
checkSuppression(names, codes, "zerodiv:xyz.cpp:3");
|
checkSuppression(names, codes, "uninitvar:xyz.cpp:3");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.experimental = true;
|
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
Loading…
Reference in New Issue