Fix issue 10207: FP: derefInvalidIteratorRedundantCheck with ternary operator (#3197)

This commit is contained in:
Paul Fultz II 2021-04-05 04:10:43 -05:00 committed by GitHub
parent f605f71e49
commit e65ea8575f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -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;

View File

@ -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"