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
|
// known value in conditional code
|
||||||
if (conditionToken->str() == "==" || conditionToken->str() == "(") {
|
if (conditionToken->str() == "==" || conditionToken->str() == "(") {
|
||||||
const Token *parent = conditionToken;
|
const Token *parent = conditionToken->astParent();
|
||||||
while (parent && parent->str() != "!")
|
while (parent && !Token::Match(parent, "!|==|!="))
|
||||||
parent = parent->astParent();
|
parent = parent->astParent();
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
value.setKnown();
|
value.setKnown();
|
||||||
|
|
|
@ -3326,6 +3326,13 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front"), 0));
|
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"
|
code = "void f(const std::vector<int> &v) {\n"
|
||||||
" if (v.empty()) {}\n"
|
" if (v.empty()) {}\n"
|
||||||
" if (!v.empty() && v[10]==0) {}\n" // <- no container size for 'v[10]'
|
" if (!v.empty() && v[10]==0) {}\n" // <- no container size for 'v[10]'
|
||||||
|
|
Loading…
Reference in New Issue