Fixed #9950 (Wrong severity for redundantAssignInSwitch)
This commit is contained in:
parent
43c4a48d48
commit
6236beeb3f
|
@ -544,7 +544,7 @@ void CheckOther::redundantCopyError(const Token *tok1, const Token* tok2, const
|
||||||
void CheckOther::redundantCopyInSwitchError(const Token *tok1, const Token* tok2, const std::string &var)
|
void CheckOther::redundantCopyInSwitchError(const Token *tok1, const Token* tok2, const std::string &var)
|
||||||
{
|
{
|
||||||
const std::list<const Token *> callstack = { tok1, tok2 };
|
const std::list<const Token *> callstack = { tok1, tok2 };
|
||||||
reportError(callstack, Severity::warning, "redundantCopyInSwitch",
|
reportError(callstack, Severity::style, "redundantCopyInSwitch",
|
||||||
"$symbol:" + var + "\n"
|
"$symbol:" + var + "\n"
|
||||||
"Buffer '$symbol' is being written before its old content has been used. 'break;' missing?", CWE563, false);
|
"Buffer '$symbol' is being written before its old content has been used. 'break;' missing?", CWE563, false);
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ void CheckOther::redundantInitializationError(const Token *tok1, const Token* to
|
||||||
void CheckOther::redundantAssignmentInSwitchError(const Token *tok1, const Token* tok2, const std::string &var)
|
void CheckOther::redundantAssignmentInSwitchError(const Token *tok1, const Token* tok2, const std::string &var)
|
||||||
{
|
{
|
||||||
const ErrorPath errorPath = { ErrorPathItem(tok1, "$symbol is assigned"), ErrorPathItem(tok2, "$symbol is overwritten") };
|
const ErrorPath errorPath = { ErrorPathItem(tok1, "$symbol is assigned"), ErrorPathItem(tok2, "$symbol is overwritten") };
|
||||||
reportError(errorPath, Severity::warning, "redundantAssignInSwitch",
|
reportError(errorPath, Severity::style, "redundantAssignInSwitch",
|
||||||
"$symbol:" + var + "\n"
|
"$symbol:" + var + "\n"
|
||||||
"Variable '$symbol' is reassigned a value before the old one has been used. 'break;' missing?", CWE563, false);
|
"Variable '$symbol' is reassigned a value before the old one has been used. 'break;' missing?", CWE563, false);
|
||||||
}
|
}
|
||||||
|
@ -715,7 +715,7 @@ void CheckOther::checkRedundantAssignmentInSwitch()
|
||||||
|
|
||||||
void CheckOther::redundantBitwiseOperationInSwitchError(const Token *tok, const std::string &varname)
|
void CheckOther::redundantBitwiseOperationInSwitchError(const Token *tok, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::warning,
|
reportError(tok, Severity::style,
|
||||||
"redundantBitwiseOperationInSwitch",
|
"redundantBitwiseOperationInSwitch",
|
||||||
"$symbol:" + varname + "\n"
|
"$symbol:" + varname + "\n"
|
||||||
"Redundant bitwise operation on '$symbol' in 'switch' statement. 'break;' missing?");
|
"Redundant bitwise operation on '$symbol' in 'switch' statement. 'break;' missing?");
|
||||||
|
|
|
@ -2580,7 +2580,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2596,7 +2596,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2725,7 +2725,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void bar() {}\n" // bar isn't noreturn
|
check("void bar() {}\n" // bar isn't noreturn
|
||||||
"void foo()\n"
|
"void foo()\n"
|
||||||
|
@ -2741,7 +2741,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a) {\n"
|
check("void foo(int a) {\n"
|
||||||
" char str[10];\n"
|
" char str[10];\n"
|
||||||
|
@ -2753,7 +2753,7 @@ private:
|
||||||
" strcpy(str, \"b'\");\n"
|
" strcpy(str, \"b'\");\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}", nullptr, false, false, false);
|
"}", nullptr, false, false, false);
|
||||||
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a) {\n"
|
check("void foo(int a) {\n"
|
||||||
" char str[10];\n"
|
" char str[10];\n"
|
||||||
|
@ -2765,7 +2765,7 @@ private:
|
||||||
" strncpy(str, \"b'\");\n"
|
" strncpy(str, \"b'\");\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a) {\n"
|
check("void foo(int a) {\n"
|
||||||
" char str[10];\n"
|
" char str[10];\n"
|
||||||
|
@ -2780,7 +2780,7 @@ private:
|
||||||
" z++;\n"
|
" z++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}", nullptr, false, false, false);
|
"}", nullptr, false, false, false);
|
||||||
// TODO ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
// TODO ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a) {\n"
|
check("void foo(int a) {\n"
|
||||||
" char str[10];\n"
|
" char str[10];\n"
|
||||||
|
@ -2856,7 +2856,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -2871,7 +2871,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -2910,7 +2910,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -2925,7 +2925,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -2964,7 +2964,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -2979,7 +2979,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -3018,7 +3018,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -3033,7 +3033,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = 1;\n"
|
" int y = 1;\n"
|
||||||
|
@ -3180,7 +3180,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar(y);\n"
|
" bar(y);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("bool f() {\n"
|
check("bool f() {\n"
|
||||||
" bool ret = false;\n"
|
" bool ret = false;\n"
|
||||||
|
@ -3217,7 +3217,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a)\n"
|
check("void foo(int a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3231,7 +3231,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a)\n"
|
check("void foo(int a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3245,7 +3245,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a)\n"
|
check("void foo(int a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -3319,7 +3319,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int a)\n"
|
check("void foo(int a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue