Skip to content

Commit 71c228a

Browse files
committed
Check for containers that modify the size using square bracket
1 parent a5b0a1c commit 71c228a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,7 @@ struct ValueFlowForwardAnalyzer : ForwardAnalyzer {
23912391
return Action::Invalid;
23922392
if (match(tok)) {
23932393
const Token* parent = tok->astParent();
2394-
if ((Token::Match(parent, "*|[") || (parent && parent->originalName() == "->")) && getIndirect(tok) <= 0)
2394+
if (astIsPointer(tok) && (Token::Match(parent, "*|[") || (parent && parent->originalName() == "->")) && getIndirect(tok) <= 0)
23952395
return Action::Read;
23962396

23972397
// Action read = Action::Read;

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4471,6 +4471,14 @@ class TestValueFlow : public TestFixture {
44714471
" ints.front();\n"
44724472
"}";
44734473
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front", ValueFlow::Value::CONTAINER_SIZE), 2));
4474+
4475+
code = "int f(bool b) {\n"
4476+
" std::map<int, int> m;\n"
4477+
" if (b)\n"
4478+
" m[0] = 1;\n"
4479+
" return m.at(0);\n"
4480+
"}\n";
4481+
ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "m . at", ValueFlow::Value::CONTAINER_SIZE), 0));
44744482
}
44754483

44764484
void valueFlowDynamicBufferSize() {

0 commit comments

Comments
 (0)