diff options
| author | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-07-13 16:17:43 +0800 |
|---|---|---|
| committer | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-07-13 16:17:43 +0800 |
| commit | 090c177003272da7d2d3b04702f35261d3952b72 (patch) | |
| tree | 534d24086f9241611f545eab36da296aade36e65 /library/alloc/src/vec/mod.rs | |
| parent | 1cab09ed9c582e7804bd0f9a6ead61129bb537d5 (diff) | |
| download | rust-090c177003272da7d2d3b04702f35261d3952b72.tar.gz rust-090c177003272da7d2d3b04702f35261d3952b72.zip | |
std::vec: Add UB check in `from_raw_parts_in`
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index da3d3596d19..6d44681fb28 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1058,6 +1058,11 @@ impl<T, A: Allocator> Vec<T, A> { #[inline] #[unstable(feature = "allocator_api", issue = "32838")] pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self { + ub_checks::assert_unsafe_precondition!( + check_library_ub, + "Vec::from_raw_parts_in requires that length <= capacity", + (length: usize = length, capacity: usize = capacity) => length <= capacity + ); unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } } } |
