Skip to content

Commit 47d4f68

Browse files
Fix #12428 FN objectIndex when accessing struct member (#8676)
1 parent 186a7a9 commit 47d4f68

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,11 @@ void CheckBufferOverrunImpl::objectIndex()
10861086

10871087
std::vector<ValueFlow::Value> values = ValueFlow::getLifetimeObjValues(obj, false, -1);
10881088
for (const ValueFlow::Value& v:values) {
1089-
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
1089+
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address && v.lifetimeKind != ValueFlow::Value::LifetimeKind::Object)
10901090
continue;
1091-
const Variable *var = v.tokvalue->variable();
1091+
const Token* varTok = nextAfterAstRightmostLeaf(v.tokvalue->astParent());
1092+
varTok = varTok ? varTok->previous() : nullptr;
1093+
const Variable *var = varTok ? varTok->variable() : nullptr;
10921094
if (!var)
10931095
continue;
10941096
if (var->isReference())

test/testbufferoverrun.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5857,7 +5857,9 @@ class TestBufferOverrun : public TestFixture {
58575857
" (void)y[1];\n"
58585858
" (void)y[2];\n"
58595859
"}\n");
5860-
TODO_ASSERT_EQUALS("error", "", errout_str());
5860+
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"
5861+
"[test.cpp:7:20] -> [test.cpp:10:12]: (error) The address of variable 's.a' is accessed at non-zero index. [objectIndex]\n",
5862+
errout_str());
58615863
}
58625864

58635865
void checkPipeParameterSize() { // #3521

0 commit comments

Comments
 (0)