Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
if (Function::returnsVoid(f))
return false;
// Member function call
if (Token::simpleMatch(ftok->previous(), ".")) {
if (Token::simpleMatch(ftok->previous(), ".") || exprDependsOnThis(ftok->next())) {
if (f->isConst())
return true;
// Check for const overloaded function that just return the const version
Expand Down
17 changes: 17 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class TestBufferOverrun : public TestFixture {
TEST_CASE(buffer_overrun_31);
TEST_CASE(buffer_overrun_32); //#10244
TEST_CASE(buffer_overrun_33); //#2019
TEST_CASE(buffer_overrun_34); //#11035
TEST_CASE(buffer_overrun_errorpath);
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
TEST_CASE(buffer_overrun_function_array_argument);
Expand Down Expand Up @@ -3120,6 +3121,22 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'z[16]' accessed at index 19, which is out of bounds.\n", errout.str());
}

// #11035
void buffer_overrun_34()
{
check("struct S {\n"
" std::vector<int> v;\n"
" int a[15] = {};\n"
" int g() const { return v.size(); }\n"
" int f(int i) const {\n"
" if (i < 0 || i >= g())\n"
" return 0;\n"
" return a[i];\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}

void buffer_overrun_errorpath() {
setMultiline();
settings0.templateLocation = "{file}:{line}:note:{info}";
Expand Down