Skip to content

Commit f2b87e9

Browse files
committed
auto merge of #16797 : nikomatsakis/rust/remove-invalid-spsc_queue-test, r=alexcrichton
This test seems to read freed memory -- the peeked variable points into the queue, but then the pop operation removes the node from the queue and moves the enclosing `T` elsewhere, invalidating the `peeked` pointer. r? @alexcrichton
2 parents 3ee047a + 5c82f48 commit f2b87e9

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

src/libsync/spsc_queue.rs

-21
Original file line numberDiff line numberDiff line change
@@ -315,27 +315,6 @@ mod test {
315315
assert_eq!(consumer.pop(), None);
316316
}
317317

318-
// This behaviour is blocked by the type system if using the safe constructor
319-
#[test]
320-
fn pop_peeked_unchecked() {
321-
let q = unsafe { Queue::new(0) };
322-
q.push(vec![1i]);
323-
q.push(vec![2]);
324-
let peeked = q.peek().unwrap();
325-
326-
assert_eq!(*peeked, vec![1]);
327-
assert_eq!(q.pop(), Some(vec![1]));
328-
329-
assert_eq!(*peeked, vec![1]);
330-
q.push(vec![7]);
331-
332-
// Note: This should actually expect 1, but this test is to highlight
333-
// the unsafety allowed by the unchecked usage. A Rust user would not
334-
// expect their peeked value to mutate like this without the type system
335-
// complaining.
336-
assert_eq!(*peeked, vec![7]);
337-
}
338-
339318
#[test]
340319
fn peek() {
341320
let (mut consumer, mut producer) = queue(0);

0 commit comments

Comments
 (0)