Skip to content

VecDeque benchmarks have UB #104096

Closed
@RalfJung

Description

@RalfJung

This benchmark function has UB:

}
#[bench]
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_pop_back_100(b: &mut test::Bencher) {
let mut deq = VecDeque::<i32>::with_capacity(101);
b.iter(|| {
deq.head = 100;
deq.tail = 0;
while !deq.is_empty() {
test::black_box(deq.pop_back());

It directly accesses private fields of VecDeque to set the head and tail pointers, but doesn't initialize the element in the middle so pop_back reads uninitialized memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions