Fixed false positive: Support assignments in CheckStl::if_find()
This commit is contained in:
parent
8885ac3eba
commit
1355f49af7
|
@ -743,11 +743,13 @@ static bool if_findCompare(const Token * const tokBack)
|
||||||
{
|
{
|
||||||
const Token *tok = tokBack->astParent();
|
const Token *tok = tokBack->astParent();
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return false;
|
return true;
|
||||||
if (tok->isComparisonOp())
|
if (tok->isComparisonOp())
|
||||||
return true;
|
return true;
|
||||||
if (tok->isArithmeticalOp()) // result is used in some calculation
|
if (tok->isArithmeticalOp()) // result is used in some calculation
|
||||||
return true; // TODO: check if there is a comparison of the result somewhere
|
return true; // TODO: check if there is a comparison of the result somewhere
|
||||||
|
if (tok->isAssignmentOp())
|
||||||
|
return if_findCompare(tok); // Go one step upwards in the AST
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1497,6 +1497,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout.str());
|
||||||
|
|
||||||
|
// error (assignment)
|
||||||
|
check("void f(std::set<int> s)\n"
|
||||||
|
"{\n"
|
||||||
|
" if (a || (x = s.find(12))) { }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout.str());
|
||||||
|
|
||||||
// ok (simple)
|
// ok (simple)
|
||||||
check("void f(std::set<int> s)\n"
|
check("void f(std::set<int> s)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1539,6 +1546,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// ok (assignment)
|
||||||
|
check("void f(std::set<int> s)\n"
|
||||||
|
"{\n"
|
||||||
|
" if (a || (x = s.find(12)) != s.end()) { }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// std::find
|
// std::find
|
||||||
|
|
Loading…
Reference in New Issue