Fixed #8689 (False positive: containerOutOfBounds after function call)

This commit is contained in:
Daniel Marjamäki 2018-09-02 14:08:34 +02:00
parent f88326c51f
commit cc402869a6
2 changed files with 15 additions and 1 deletions

View File

@ -3463,7 +3463,14 @@ static bool isContainerSizeChangedByFunction(const Token *tok)
parent = parent->astParent();
while (parent && parent->str() == ",")
parent = parent->astParent();
return parent && Token::Match(parent->previous(), "%name% (");
if (!parent)
return false;
if (Token::Match(parent->previous(), "%name% ("))
return true;
// some unsimplified template function, assume it modifies the container.
if (Token::simpleMatch(parent->previous(), ">") && parent->linkAt(-1))
return true;
return false;
}
static void valueFlowContainerReverse(const Token *tok, unsigned int containerId, const ValueFlow::Value &value, const Settings *settings)

View File

@ -3372,6 +3372,13 @@ private:
"}";
ASSERT(tokenValues(code, "x . front").empty());
code = "void f() {\n" // #8689
" std::list<int> x;\n"
" f<ns::a>(x);\n"
" x.front();\n" // <- unknown container size
"}";
ASSERT(tokenValues(code, "x . front").empty());
code = "void f(std::vector<int> ints) {\n" // #8697
" if (ints.empty())\n"
" abort() << 123;\n"