blob: 1bc8e6ada10d9df390fbc1ea5deb53baa13d876c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
//@ run-crash
//@ compile-flags: -Cdebug-assertions=yes
//@ error-pattern: unsafe precondition(s) violated: Vec::from_raw_parts_in requires that length <= capacity
//@ revisions: vec_from_raw_parts vec_from_raw_parts_in string_from_raw_parts
#![feature(allocator_api)]
fn main() {
let ptr = std::ptr::null_mut::<u8>();
// Test Vec::from_raw_parts with length > capacity
unsafe {
#[cfg(vec_from_raw_parts)]
let _vec = Vec::from_raw_parts(ptr, 10, 5);
}
// Test Vec::from_raw_parts_in with length > capacity
unsafe {
let alloc = std::alloc::Global;
#[cfg(vec_from_raw_parts_in)]
let _vec = Vec::from_raw_parts_in(ptr, 10, 5, alloc);
}
// Test String::from_raw_parts with length > capacity
// Because it calls Vec::from_raw_parts, it should also fail
unsafe {
#[cfg(string_from_raw_parts)]
let _vec = String::from_raw_parts(ptr, 10, 5);
}
}
|