-
Notifications
You must be signed in to change notification settings - Fork 24
Fix UB in documentation example #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing it and adding miri to CI.
I've updated the docs. What do you think?
src/ascii_string.rs
Outdated
@@ -65,6 +65,7 @@ impl AsciiString { | |||
/// | |||
/// * The memory at `buf` need to have been previously allocated by the same allocator this | |||
/// library uses. | |||
/// * `buf` must be obtained from a valid `&mut` reference to guarentee exclusive ownership. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either this is implied by *mut
, or that miri is stricter than the language currently is.
The docs for String::from_raw_parts()
doesn't mention this.
src/ascii_string.rs
Outdated
@@ -98,8 +99,8 @@ impl AsciiString { | |||
pub unsafe fn from_raw_parts(buf: *mut AsciiChar, length: usize, capacity: usize) -> Self { | |||
AsciiString { | |||
// SAFETY: Caller guarantees `buf` was previously allocated by this library, | |||
// that `buf` contains `length` valid ascii elements and has a total | |||
// capacity of `capacity` elements. | |||
// is a unique pointer, `buf` contains `length` valid ascii elements, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term unique pointer isn't really used in rust, and
The example creates a new `AsciiString::from_raw_parts` using a shared reference casted to a mutable pointer. This changes the example to use an exclusive reference/pointer.
That's probably best, I updated the docs while I was changing the example but best to match |
The example creates a new
AsciiString::from_raw_parts
using a shared reference casted to a mutable pointer. This changes the example to use an exclusive reference/pointer.