Fixed #8688 (False positive: containerOutOfBounds)
This commit is contained in:
parent
c5154286da
commit
2f834c3c3b
|
@ -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();
|
||||
|
|
|
@ -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]'
|
||||
|
|
Loading…
Reference in New Issue