Skip to content

Commit a241be0

Browse files
committed
Fixed #9434 (False positive: Out of bounds access when using const pointer)
1 parent 88a3b4c commit a241be0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5423,7 +5423,9 @@ static bool isContainerSizeChangedByFunction(const Token *tok, int depth = 20)
54235423
if (arg) {
54245424
if (!arg->isReference() && !addressOf)
54255425
return false;
5426-
if (arg->isConst())
5426+
if (!addressOf && arg->isConst())
5427+
return false;
5428+
if (arg->valueType() && arg->valueType()->constness == 1)
54275429
return false;
54285430
const Scope * scope = fun->functionScope;
54295431
if (scope) {

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,6 +4077,14 @@ class TestValueFlow : public TestFixture {
40774077
"}";
40784078
ASSERT(tokenValues(code, "x . front").empty());
40794079

4080+
code = "void g(std::list<int>* const);\n" // #9434
4081+
"void f() {\n"
4082+
" std::list<int> x;\n"
4083+
" g(&x);\n"
4084+
" x.front();\n"
4085+
"}";
4086+
ASSERT(tokenValues(code, "x . front").empty());
4087+
40804088
code = "void g(const std::list<int>&);\n"
40814089
"void f() {\n"
40824090
" std::list<int> x;\n"

0 commit comments

Comments
 (0)