about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/vec.rs
AgeCommit message (Collapse)AuthorLines
2025-09-22avoid violating `slice::from_raw_parts` safety contract in `Vec::extract_if`Petros Angelatos-0/+10
The implementation of the `Vec::extract_if` iterator violates the safety contract adverized by `slice::from_raw_parts` by always constructing a mutable slice for the entire length of the vector even though that span of memory can contain holes from items already drained. The safety contract of `slice::from_raw_parts` requires that all elements must be properly initialized. As an example we can look at the following code: ```rust let mut v = vec![Box::new(0u64), Box::new(1u64)]; for item in v.extract_if(.., |x| **x == 0) { drop(item); } ``` In the second iteration a `&mut [Box<u64>]` slice of length 2 will be constructed. The first slot of the slice contains the bitpattern of an already deallocated box, which is invalid. This fixes the issue by only creating references to valid items and using pointer manipulation for the rest. I have also taken the liberty to remove the big `unsafe` blocks in place of targetted ones with a SAFETY comment. The approach closely mirrors the implementation of `Vec::retain_mut`. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2025-05-04Remove -Zunique-is-uniqueJohannes Hostert-2/+1
2023-07-03vec tets: ensure pointer is still writeableRalf Jung-6/+6
2023-06-28Unique gets special treatment when -Zmiri-unique-is-uniqueNeven Villani-2/+3
2023-03-16TB: select tests to run both TB and SBNeven Villani-0/+2
2023-01-17add miri regression testThe 8472-0/+6
2022-12-24fix warningsRalf Jung-1/+1
2022-12-23fix one more unaligned self.ptr, and add testsRalf Jung-0/+14
2022-12-23fix IntoIter::drop on high-alignment ZSTRalf Jung-7/+11
2022-09-21Add 'src/tools/miri/' from commit '75dd959a3a40eb5b4574f8d2e23aa6efbeb33573'Oli Scherer-0/+176
git-subtree-dir: src/tools/miri git-subtree-mainline: 3f3167fb59341ac3240ca1774f48e8c053219131 git-subtree-split: 75dd959a3a40eb5b4574f8d2e23aa6efbeb33573