fix: UB in safe rust!

This commit is contained in:
Janis 2025-01-19 18:43:09 +01:00
parent 75e75ec706
commit 0db6b7790d

View file

@ -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,
}
}
}