Fix 11358: FP containerOutOfBounds for container passed by pointer (#4626)

This commit is contained in:
Paul Fultz II 2022-12-09 12:43:21 -06:00 committed by GitHub
parent 40a69e5afb
commit 3f88744851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -7689,6 +7689,14 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
} }
} }
int getIndirect(const Token* tok) const override
{
if (tok->valueType()) {
return tok->valueType()->pointer;
}
return ValueFlowAnalyzer::getIndirect(tok);
}
Action isModified(const Token* tok) const override { Action isModified(const Token* tok) const override {
Action read = Action::Read; Action read = Action::Read;
// An iterator won't change the container size // An iterator won't change the container size

View File

@ -886,6 +886,13 @@ private:
" v[0];\n" " v[0];\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkNormal("void f(std::vector<int>* v) {\n"
" if (v->empty())\n"
" v->push_back(1);\n"
" auto x = v->back();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void outOfBoundsSymbolic() void outOfBoundsSymbolic()