Skip to content

Commit 745bbaf

Browse files
committed
Add case of dangling pointers
1 parent 33af700 commit 745bbaf

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

library/core/src/str/lossy.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ impl FusedIterator for Utf8Chunks<'_> {}
301301
#[stable(feature = "utf8_chunks", since = "1.79.0")]
302302
impl fmt::Debug for Utf8Chunks<'_> {
303303
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
304-
f.debug_struct("Utf8Chunks").field("source", &self.debug()).finish()
304+
f.debug_struct("Utf8Chunks")
305+
.field("source", &self.debug())
306+
.finish()
305307
}
306308
}
307309

@@ -312,14 +314,23 @@ pub mod verify {
312314

313315
#[kani::proof]
314316
pub fn check_next() {
315-
// TODO: ARR_SIZE can be `std::usize::MAX` with cbmc argument
316-
// `--arrays-uf-always`
317-
const ARR_SIZE: usize = 1000;
318-
let mut x: [u8; ARR_SIZE] = kani::any();
319-
let mut xs = kani::slice::any_slice_of_array_mut(&mut x);
320-
let mut chunks = xs.utf8_chunks();
321-
unsafe {
322-
chunks.next();
317+
if kani::any() {
318+
// TODO: ARR_SIZE can be `std::usize::MAX` with cbmc argument
319+
// `--arrays-uf-always`
320+
const ARR_SIZE: usize = 1000;
321+
let mut x: [u8; ARR_SIZE] = kani::any();
322+
let mut xs = kani::slice::any_slice_of_array_mut(&mut x);
323+
let mut chunks = xs.utf8_chunks();
324+
unsafe {
325+
chunks.next();
326+
}
327+
} else {
328+
let ptr = kani::any_where::<usize, _>(|val| *val != 0) as *const u8;
329+
kani::assume(ptr.is_aligned());
330+
unsafe {
331+
let mut chunks = crate::slice::from_raw_parts(ptr, 0).utf8_chunks();
332+
chunks.next();
333+
}
323334
}
324335
}
325336
}

0 commit comments

Comments
 (0)