Skip to content

Commit c318cf6

Browse files
Fix #12738 FP containerOutOfBounds for std::vector with braced initializer (#6409)
1 parent a8407ff commit c318cf6

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8788,7 +8788,7 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
87888788
bool initList = true;
87898789
// Try to disambiguate init list from constructor
87908790
if (args.size() < 4) {
8791-
initList = !isIteratorPair(args) && !(args.size() < 3 && astIsIntegral(args[0], false));
8791+
initList = !isIteratorPair(args);
87928792
const Token* containerTypeToken = valueType->containerTypeToken;
87938793
if (valueType->container->stdStringLike) {
87948794
initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]);

test/teststl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ class TestStl : public TestFixture {
926926
" return s[2];\n"
927927
"}\n");
928928
ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression 's[2]' because 's' is empty.\n", errout_str());
929+
930+
checkNormal("void f() {\n" // #12738
931+
" std::vector<double> v{ 0, 0.1 };\n"
932+
" (void)v[0];\n"
933+
"}\n");
934+
ASSERT_EQUALS("", errout_str());
929935
}
930936

931937
void outOfBoundsSymbolic()

0 commit comments

Comments
 (0)