Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,12 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {
}

// SAFETY: Outer caller has provided a pointer to a valid C string.
unsafe { strlen(s) }
let len = unsafe { strlen(s) };
// SAFETY: The length is at most the size of the allocation containing the string, which
// must fit in `isize::MAX`. Since the nul-terminator is not included in `len`, it's <
// rather than <=.
unsafe { crate::hint::assert_unchecked(len < isize::MAX as usize) };
len
}
)
}
Expand Down
Loading