From 1ecf03f4f84dcdb11f4c93c436167cd36cbca78c Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Wed, 16 Oct 2024 06:55:50 +0300 Subject: [PATCH] Remove potential panic in `split_init` --- src/buffer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/buffer.rs b/src/buffer.rs index d7c0924ce..78503e63f 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -15,7 +15,8 @@ pub(super) unsafe fn split_init( buf: &mut [MaybeUninit], init: usize, ) -> (&mut [u8], &mut [MaybeUninit]) { - let (init, uninit) = buf.split_at_mut(init); + debug_assert!(buf.len() <= init); + let (init, uninit) = buf.split_at_mut_unchecked(init); let init = slice::from_raw_parts_mut(init.as_mut_ptr().cast::(), init.len()); (init, uninit) }