Skip to content
18 changes: 11 additions & 7 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,13 +1063,17 @@ mod verify {
let c_str: &CStr = unsafe { &*(slice as *const [u8] as *const CStr) };

let len = slice.len();
// Oracle #1 (structural): valid iff the FIRST nul sits at the final
// index. Phrased with `position` — not the invariant's own form — so
// this is an independent cross-check, not a restatement.
let first_nul_at_end = match slice.iter().position(|&b| b == 0) {
Some(pos) => pos == len - 1,
None => false,
};
// Oracle #1 scans backwards to find the first NUL independently of
// the constructor's forward search.
let mut first_nul = None;
let mut i = len;
while i != 0 {
i -= 1;
if slice[i] == 0 {
first_nul = Some(i);
}
}
let first_nul_at_end = first_nul.is_some_and(|pos| pos + 1 == len);
assert_eq!(c_str.is_safe(), first_nul_at_end);

// Oracle #2 (semantic): the invariant accepts exactly the byte
Expand Down
15 changes: 15 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,21 @@ impl<T> *mut [T] {
/// ```
#[inline(always)]
#[unstable(feature = "raw_slice_split", issue = "95595")]
#[cfg_attr(kani, kani::modifies())]
#[requires(
mid <= self.len()
&& !self.as_mut_ptr().is_null()
&& crate::ub_checks::can_write(self)
)]
#[ensures(|parts: &(*mut [T], *mut [T])| {
let (head, tail) = *parts;
head.as_mut_ptr() == self.as_mut_ptr()
&& head.len() == mid
&& tail.as_mut_ptr() == self.as_mut_ptr().wrapping_add(mid)
&& tail.len() == self.len().saturating_sub(mid)
&& crate::ub_checks::can_write(head)
&& crate::ub_checks::can_write(tail)
})]
pub unsafe fn split_at_mut_unchecked(self, mid: usize) -> (*mut [T], *mut [T]) {
let len = self.len();
let ptr = self.as_mut_ptr();
Expand Down
Loading
Loading