-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.
Description
split_at_unchecked calls ptr.add(mid) which may be UB if mid is the length of the slice. Making it ptr.wrapping_add(mid) or changing the precondition to mid < len would fix this.
rust/library/core/src/slice/mod.rs
Lines 2069 to 2079 in e7f4317
| let len = self.len(); | |
| let ptr = self.as_ptr(); | |
| assert_unsafe_precondition!( | |
| check_library_ub, | |
| "slice::split_at_unchecked requires the index to be within the slice", | |
| (mid: usize = mid, len: usize = len) => mid <= len, | |
| ); | |
| // SAFETY: Caller has to check that `0 <= mid <= self.len()` | |
| unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), unchecked_sub(len, mid))) } |
Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.