diff options
| author | Albin Hedman <albin9604@gmail.com> | 2020-12-26 01:59:08 +0100 |
|---|---|---|
| committer | Albin Hedman <albin9604@gmail.com> | 2020-12-26 03:45:51 +0100 |
| commit | 5e27765ddfbeb524629ecb78c430fbe9c765232b (patch) | |
| tree | 81ef49d3c8af66f0a682948e5c8239b27af55263 /src/test/ui/const-ptr | |
| parent | 1975a6e710d6fbb583a415edc3efed1e8970296a (diff) | |
| download | rust-5e27765ddfbeb524629ecb78c430fbe9c765232b.tar.gz rust-5e27765ddfbeb524629ecb78c430fbe9c765232b.zip | |
Add tests
Diffstat (limited to 'src/test/ui/const-ptr')
| -rw-r--r-- | src/test/ui/const-ptr/out_of_bounds_read.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/const-ptr/out_of_bounds_read.stderr | 54 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/const-ptr/out_of_bounds_read.rs b/src/test/ui/const-ptr/out_of_bounds_read.rs new file mode 100644 index 00000000000..183aa9e5122 --- /dev/null +++ b/src/test/ui/const-ptr/out_of_bounds_read.rs @@ -0,0 +1,16 @@ +// error-pattern: any use of this value will cause an error + +#![feature(const_ptr_read)] +#![feature(const_ptr_offset)] + +fn main() { + use std::ptr; + + const DATA: [u32; 1] = [42]; + + const PAST_END_PTR: *const u32 = unsafe { DATA.as_ptr().add(1) }; + + const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; + const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; + const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; +} diff --git a/src/test/ui/const-ptr/out_of_bounds_read.stderr b/src/test/ui/const-ptr/out_of_bounds_read.stderr new file mode 100644 index 00000000000..ca65a079947 --- /dev/null +++ b/src/test/ui/const-ptr/out_of_bounds_read.stderr @@ -0,0 +1,54 @@ +error: any use of this value will cause an error + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | unsafe { copy_nonoverlapping(src, dst, count) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 + | inside `copy_nonoverlapping::<u32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL + | inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | inside `_READ` at $DIR/out_of_bounds_read.rs:13:33 + | + ::: $DIR/out_of_bounds_read.rs:13:5 + | +LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; + | ------------------------------------------------------ + | + = note: `#[deny(const_err)]` on by default + +error: any use of this value will cause an error + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | unsafe { copy_nonoverlapping(src, dst, count) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 + | inside `copy_nonoverlapping::<u32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL + | inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | inside `ptr::const_ptr::<impl *const u32>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL + | inside `_CONST_READ` at $DIR/out_of_bounds_read.rs:14:39 + | + ::: $DIR/out_of_bounds_read.rs:14:5 + | +LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; + | -------------------------------------------------------- + +error: any use of this value will cause an error + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | unsafe { copy_nonoverlapping(src, dst, count) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4 + | inside `copy_nonoverlapping::<u32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL + | inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | inside `ptr::mut_ptr::<impl *mut u32>::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + | inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37 + | + ::: $DIR/out_of_bounds_read.rs:15:5 + | +LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; + | -------------------------------------------------------------------- + +error: aborting due to 3 previous errors + |
