Fix issue 10207: FP: derefInvalidIteratorRedundantCheck with ternary operator (#3197)
This commit is contained in:
parent
f605f71e49
commit
e65ea8575f
|
@ -95,12 +95,6 @@ struct ReverseTraversal {
|
|||
bool checkThen, checkElse;
|
||||
std::tie(checkThen, checkElse) = evalCond(condTok);
|
||||
|
||||
if (!checkThen && !checkElse) {
|
||||
Analyzer::Action action = analyzeRecursive(condTok);
|
||||
if (action.isRead() || action.isModified())
|
||||
return parent;
|
||||
}
|
||||
|
||||
if (parent->str() == "?") {
|
||||
if (checkElse && opSide == 1)
|
||||
return parent;
|
||||
|
|
|
@ -3787,6 +3787,12 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2.\n", errout.str());
|
||||
|
||||
check("void f(int v, std::map<int, int> &items) {\n"
|
||||
" for (auto it = items.begin(); it != items.end();)\n"
|
||||
" (it->first == v) ? it = items.erase(it) : ++it;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(std::string s) {\n"
|
||||
" for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {\n"
|
||||
" if (i != s.end() && (i + 1) != s.end() && *(i + 1) == *i) {\n"
|
||||
|
|
Loading…
Reference in New Issue