-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
CStr::from_ptr()
with CStr::from_bytes_with_nul()
`CStr::from_ptr()` is `unsafe` because it reads a raw pointer, and searches for a terminating nul character in the pointed region of memory. This is unnecessary as both calls already initialize a given number of characters and terminate with a nul, allowing us to pass a sized and initialized slice (without casting `*const MaybeUninit<u8>` to `*const u8`) directly to `CStr::from_bytes_with_nul()` (available since Rust 1.10, unlike `CStr::from_bytes_until_nul()` which was only stabilized in 1.69). Unfortunately all `std` helper APIs to initialize slices of `MaybeUninit` are still unstable, making this less ideal to write at the moment.
- Loading branch information
Showing
1 changed file
with
48 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters