Skip to content

Commit 76fe221

Browse files
Fix #13450 FP containerOutOfBounds with nested std::vector (danmar#7118)
1 parent 53d1286 commit 76fe221

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6428,9 +6428,9 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
64286428
std::vector<const Token*> args = getArguments(tok);
64296429
if (args.empty())
64306430
return {makeContainerSizeValue(std::size_t{0}, known)};
6431-
bool initList = true;
6431+
bool initList = tok->str() == "{";
64326432
// Try to disambiguate init list from constructor
6433-
if (args.size() < 4) {
6433+
if (initList && args.size() < 4) {
64346434
initList = !isIteratorPair(args);
64356435
const Token* containerTypeToken = valueType->containerTypeToken;
64366436
if (valueType->container->stdStringLike) {

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,6 +7121,12 @@ class TestValueFlow : public TestFixture {
71217121
" return x;\n"
71227122
"}";
71237123
ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 2));
7124+
7125+
code = "auto f() {\n" // #13450
7126+
" auto v = std::vector<std::vector<S*>>(3, std::vector<S*>());\n"
7127+
" return v[2];\n"
7128+
"}";
7129+
ASSERT(isKnownContainerSizeValue(tokenValues(code, "v ["), 3).empty());
71247130
}
71257131

71267132
void valueFlowContainerElement()

0 commit comments

Comments
 (0)