Fixed #8688 (False positive: containerOutOfBounds)

This commit is contained in:
Daniel Marjamäki 2018-08-13 21:27:29 +02:00
parent c5154286da
commit 2f834c3c3b
2 changed files with 9 additions and 2 deletions

View File

@ -3617,8 +3617,8 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold
// known value in conditional code
if (conditionToken->str() == "==" || conditionToken->str() == "(") {
const Token *parent = conditionToken;
while (parent && parent->str() != "!")
const Token *parent = conditionToken->astParent();
while (parent && !Token::Match(parent, "!|==|!="))
parent = parent->astParent();
if (!parent) {
value.setKnown();

View File

@ -3326,6 +3326,13 @@ private:
"}";
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front"), 0));
code = "void f(const std::list<int> &ints) {\n"
" if (ints.empty() == false) {\n"
" ints.front();\n" // <- container is not empty
" }\n"
"}";
ASSERT(tokenValues(code, "ints . front").empty());
code = "void f(const std::vector<int> &v) {\n"
" if (v.empty()) {}\n"
" if (!v.empty() && v[10]==0) {}\n" // <- no container size for 'v[10]'