Skip to content

Commit 7b344ad

Browse files
committed
debug_assert!(length <= capacity) in Vec::from_raw_parts
This hopefully helps to catch cases where these arguments are accidentally swapped.
1 parent d423c81 commit 7b344ad

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ impl<T, A: Allocator> Vec<T, A> {
944944
#[inline]
945945
#[unstable(feature = "allocator_api", issue = "32838")]
946946
pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self {
947+
debug_assert!(length <= capacity, "Vec length must be less or equal to its capacity");
947948
unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
948949
}
949950

0 commit comments

Comments
 (0)