Skip to content

Commit 3f88744

Browse files
authored
Fix 11358: FP containerOutOfBounds for container passed by pointer (#4626)
1 parent 40a69e5 commit 3f88744

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7689,6 +7689,14 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
76897689
}
76907690
}
76917691

7692+
int getIndirect(const Token* tok) const override
7693+
{
7694+
if (tok->valueType()) {
7695+
return tok->valueType()->pointer;
7696+
}
7697+
return ValueFlowAnalyzer::getIndirect(tok);
7698+
}
7699+
76927700
Action isModified(const Token* tok) const override {
76937701
Action read = Action::Read;
76947702
// An iterator won't change the container size

test/teststl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,13 @@ class TestStl : public TestFixture {
886886
" v[0];\n"
887887
"}\n");
888888
ASSERT_EQUALS("", errout.str());
889+
890+
checkNormal("void f(std::vector<int>* v) {\n"
891+
" if (v->empty())\n"
892+
" v->push_back(1);\n"
893+
" auto x = v->back();\n"
894+
"}\n");
895+
ASSERT_EQUALS("", errout.str());
889896
}
890897

891898
void outOfBoundsSymbolic()

0 commit comments

Comments
 (0)