Fix incorrect internal clear inside RingBufferImplemenetation#3116
Fix incorrect internal clear inside RingBufferImplemenetation#3116InvincibleRMC wants to merge 1 commit intorollingfrom
RingBufferImplemenetation#3116Conversation
Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
|
Pulls: #3116 |
fujitatomoya
left a comment
There was a problem hiding this comment.
i think this is right thing to do.
the ring buffer's design relies on this vector staying at a fixed size equal to capacity_ to logically track which elements are valid. calling std::vector::clear() sets the vector's size to 0 and deallocates elements, which breaks the class invariant that ring_buffer_.size() == capacity_. after a clear() call on the old code, any subsequent enqueue() would index into ring_buffer_[write_index_] on a now-empty vector — that's undefined behavior (out-of-bounds access).
can we also consider to add the regression test verifies this undefined behavior?
this actually rolls back part of #2837
|
Agree with @fujitatomoya's summary and also second adding a test just to make sure that we don't regress here. |
|
Yeah will try to come up with UB test. This definitely raises the question of what does clearing a ring buffer really mean. Since the current implementation doesn't support any resizing methods I don't think destroying the internal buffer makes sense and should maybe even be Does |
Description
ros2/ci#838 (comment)
Calling the internal clear could lead to index out of bounds. Caught with gcc15 on Ubuntu26.
Is this user-facing behavior change?
Did you use Generative AI?
Additional Information