Fixed #7384 (confuses syntax with variable name / "variable '(' is less than zero")

This commit is contained in:
Daniel Marjamäki 2018-12-31 18:36:06 +01:00
parent ed514644b8
commit ac357a96f7
2 changed files with 15 additions and 15 deletions

View File

@ -2058,16 +2058,16 @@ void CheckOther::unsignedLessThanZeroError(const Token *tok, const std::string &
if (inconclusive) {
reportError(tok, Severity::style, "unsignedLessThanZero",
"$symbol:" + varname + "\n"
"Checking if unsigned variable '$symbol' is less than zero. This might be a false warning.\n"
"Checking if unsigned variable '$symbol' is less than zero. An unsigned "
"Checking if unsigned expression '$symbol' is less than zero. This might be a false warning.\n"
"Checking if unsigned expression '$symbol' is less than zero. An unsigned "
"variable will never be negative so it is either pointless or an error to check if it is. "
"It's not known if the used constant is a template parameter or not and therefore "
"this message might be a false warning.", CWE570, true);
} else {
reportError(tok, Severity::style, "unsignedLessThanZero",
"$symbol:" + varname + "\n"
"Checking if unsigned variable '$symbol' is less than zero.\n"
"The unsigned variable '$symbol' will never be negative so it "
"Checking if unsigned expression '$symbol' is less than zero.\n"
"The unsigned expression '$symbol' will never be negative so it "
"is either pointless or an error to check if it is.", CWE570, false);
}
}

View File

@ -4779,7 +4779,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x) {\n"
@ -4795,7 +4795,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x) {\n"
@ -4828,7 +4828,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4844,7 +4844,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4877,7 +4877,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4893,7 +4893,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4926,7 +4926,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4942,7 +4942,7 @@ private:
" return true;\n"
" return false;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned variable 'x' is less than zero.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str());
check(
"bool foo(int x, bool y) {\n"
@ -4978,7 +4978,7 @@ private:
check(code, nullptr, false, false);
ASSERT_EQUALS("", errout.str());
check(code, nullptr, false, true);
ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Checking if unsigned variable 'x' is less than zero. This might be a false warning.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Checking if unsigned expression 'x' is less than zero. This might be a false warning.\n", errout.str());
}
}
@ -7238,8 +7238,8 @@ private:
" return;\n"
" }\n"
"}", "test.c");
ASSERT_EQUALS("[test.c:8]: (style) Checking if unsigned variable 'd.n' is less than zero.\n"
"[test.c:12]: (style) Checking if unsigned variable 'd.n' is less than zero.\n",
ASSERT_EQUALS("[test.c:8]: (style) Checking if unsigned expression 'd.n' is less than zero.\n"
"[test.c:12]: (style) Checking if unsigned expression 'd.n' is less than zero.\n",
errout.str());
}