Skip to content
Open
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
6 changes: 4 additions & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,11 @@ void CheckBufferOverrunImpl::objectIndex()

std::vector<ValueFlow::Value> values = ValueFlow::getLifetimeObjValues(obj, false, -1);
for (const ValueFlow::Value& v:values) {
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address && v.lifetimeKind != ValueFlow::Value::LifetimeKind::Object)
continue;
const Variable *var = v.tokvalue->variable();
const Token* varTok = nextAfterAstRightmostLeaf(v.tokvalue->astParent());
varTok = varTok ? varTok->previous() : nullptr;
const Variable *var = varTok ? varTok->variable() : nullptr;
if (!var)
continue;
if (var->isReference())
Expand Down
4 changes: 3 additions & 1 deletion test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5857,7 +5857,9 @@ class TestBufferOverrun : public TestFixture {
" (void)y[1];\n"
" (void)y[2];\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout_str());
ASSERT_EQUALS("[test.cpp:7:20] -> [test.cpp:9:12]: (error) The address of variable 's.a' is accessed at non-zero index. [objectIndex]\n"
"[test.cpp:7:20] -> [test.cpp:10:12]: (error) The address of variable 's.a' is accessed at non-zero index. [objectIndex]\n",
errout_str());
}

void checkPipeParameterSize() { // #3521
Expand Down
Loading