Skip to content

Conversation

@lennin-cp
Copy link

Fix Coverity CID 723248: After advancing the iterator kit past the end and breaking from the innermost loop, the middle loop could continue and dereference the invalid iterator on the next iteration.

Add a check after the inner loop to break out of the middle loop when kit reaches kinfo.end().

🤖 Generated with Claude Code

Fix Coverity CID 723248: After advancing the iterator `kit` past the end
and breaking from the innermost loop, the middle loop could continue and
dereference the invalid iterator on the next iteration.

Add a check after the inner loop to break out of the middle loop when
`kit` reaches `kinfo.end()`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@lennin-cp lennin-cp requested review from Copilot and zma2 December 17, 2025 21:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Coverity-detected defect (CID 723248) involving an invalid iterator dereference in the ZeMetricProfiler class. The issue occurs when an iterator is advanced past the end of a container in an inner loop, then potentially dereferenced in subsequent iterations of the middle loop.

Key Changes:

  • Added an iterator bounds check after the inner loop to prevent dereferencing an invalid iterator

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1158 to +1161
value += samples[i];
if (kit == kinfo.end()) {
break;
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check occurs after value += samples[i] at line 1158, but the iterator kit is used or incremented in the inner loop above. If kit was incremented to kinfo.end() in the inner loop and the code breaks from it, then continues to line 1158, there's a potential that kit might be dereferenced between the break point and this check. Verify that no dereference of kit occurs at line 1158 or ensure this check happens immediately after the inner loop before any potential use of kit.

Suggested change
value += samples[i];
if (kit == kinfo.end()) {
break;
}
if (kit == kinfo.end()) {
break;
}
value += samples[i];

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants