assignmentInCondition: Clarify error message
This commit is contained in:
parent
72802554c9
commit
c8e661f61f
|
@ -1716,6 +1716,8 @@ void CheckCondition::checkAssignmentInCondition()
|
|||
// Is this assignment of container/iterator?
|
||||
if (!tok->valueType())
|
||||
continue;
|
||||
if (tok->valueType()->pointer > 0)
|
||||
continue;
|
||||
if (tok->valueType()->type != ValueType::Type::CONTAINER && tok->valueType()->type != ValueType::Type::ITERATOR)
|
||||
continue;
|
||||
|
||||
|
@ -1732,11 +1734,13 @@ void CheckCondition::checkAssignmentInCondition()
|
|||
|
||||
void CheckCondition::assignmentInCondition(const Token *eq)
|
||||
{
|
||||
std::string expr = eq ? eq->expressionString() : "x=y";
|
||||
|
||||
reportError(
|
||||
eq,
|
||||
Severity::style,
|
||||
"assignmentInCondition",
|
||||
"Assignment in condition should probably be comparison.",
|
||||
"Suspicious assignment in condition. Condition '" + expr + "' is always true.",
|
||||
CWE571,
|
||||
Certainty::normal);
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ private:
|
|||
"- Comparisons of modulo results that are always true/false.\n"
|
||||
"- Known variable values => condition is always true/false\n"
|
||||
"- Invalid test for overflow. Some mainstream compilers remove such overflow tests when optimising code.\n"
|
||||
"- Assignment of container/iterator in condition should probably be comparison.\n";
|
||||
"- Suspicious assignment of container/iterator in condition => condition is always true.\n";
|
||||
}
|
||||
};
|
||||
/// @}
|
||||
|
|
|
@ -4160,7 +4160,12 @@ private:
|
|||
check("void f(std::string s) {\n"
|
||||
" if (s=\"123\"){}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Assignment in condition should probably be comparison.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious assignment in condition. Condition 's=\"123\"' is always true.\n", errout.str());
|
||||
|
||||
check("void f(std::string *p) {\n"
|
||||
" if (p=foo()){}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue