STL: Fixed false positive when using string::find

This commit is contained in:
Daniel Marjamäki 2011-12-27 11:02:43 +01:00
parent f6b201bb3b
commit 0bf8e6206c
2 changed files with 14 additions and 0 deletions

View File

@ -60,6 +60,13 @@ void CheckStl::iterators()
if (iteratorId == 0 || containerId == 0)
continue;
// check that it's an iterator..
{
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(iteratorId);
if (!var || !Token::Match(var->nameToken()->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator"))
continue;
}
// the validIterator flag says if the iterator has a valid value or not
bool validIterator = true;
const Token* validatingToken = 0;

View File

@ -361,6 +361,13 @@ private:
" if (it == map2.end()) { }"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Same iterator is used with both map1 and map2\n", errout.str());
check("void f(std::string &s) {\n"
" int pos = s.find(x);\n"
" s.erase(pos);\n"
" s.erase(pos);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing invalid pointer