Skip to content

Commit 2daa9cd

Browse files
Fix #11335 FN arrayIndexOutOfBounds with array of pointers (regression) (danmar#8323)
1 parent b99ce96 commit 2daa9cd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/vf_common.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ namespace ValueFlow
230230
setTokenValue(tok->tokAt(4), std::move(value), settings);
231231
}
232232
} else if (Token::Match(tok2, "%var% )")) {
233-
const Variable *var = tok2->variable();
234-
// only look for single token types (no pointers or references yet)
235-
if (var && var->typeStartToken() == var->typeEndToken()) {
233+
if (const Variable *var = tok2->variable()) {
236234
// find the size of the type
237235
size_t size = 0;
238236
if (var->isEnumType()) {

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,15 @@ class TestValueFlow : public TestFixture {
17421742
values = tokenValues(code, "( D )");
17431743
ASSERT_EQUALS(1U, values.size());
17441744
TODO_ASSERT_EQUALS(2 * settings.platform.sizeof_pointer, 1, values.back().intvalue);
1745+
1746+
code = "int f() {\n" // #11335
1747+
" int* a[2];"
1748+
" return sizeof(a);\n"
1749+
"}";
1750+
values = tokenValues(code, "( a");
1751+
ASSERT_EQUALS(1U, values.size());
1752+
ASSERT_EQUALS(2 * settings.platform.sizeof_pointer, values.back().intvalue);
1753+
ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Known, values.back().valueKind);
17451754
}
17461755

17471756
void valueFlowComma()

0 commit comments

Comments
 (0)