From 0db6b7790da252c3558647c0239e95f5d24e9240 Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 19 Jan 2025 18:43:09 +0100 Subject: [PATCH] fix: UB in safe rust! --- crates/renderer/src/util.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/renderer/src/util.rs b/crates/renderer/src/util.rs index 08d9982..7cafc4d 100644 --- a/crates/renderer/src/util.rs +++ b/crates/renderer/src/util.rs @@ -558,14 +558,19 @@ impl CStringList { let mut bytes = vec![]; let mut strings = vec![]; i.into_iter().for_each(|s| { - strings.push(bytes.as_ptr_range().end as *const i8); + let start = bytes.len(); bytes.extend_from_slice(s.as_ref().as_bytes()); bytes.push(0); + strings.push(start); }); + let bytes = bytes.into_boxed_slice(); Self { - strings: strings.into_boxed_slice(), - bytes: bytes.into_boxed_slice(), + strings: strings + .into_iter() + .map(|offset| unsafe { bytes.as_ptr().offset(offset as isize) as *const i8 }) + .collect(), + bytes, } } }