-
Notifications
You must be signed in to change notification settings - Fork 435
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
Fix warnings in str.rs and binding_generated.rs #343
Conversation
This comment has been minimized.
This comment has been minimized.
Related #340 |
Thanks a ton for these! For |
rust/kernel/str.rs
Outdated
@@ -89,8 +89,13 @@ impl CStr { | |||
/// must not be mutated. | |||
#[inline] | |||
pub unsafe fn from_char_ptr<'a>(ptr: *const c_types::c_char) -> &'a Self { | |||
let len = bindings::strlen(ptr) + 1; | |||
Self::from_bytes_with_nul_unchecked(core::slice::from_raw_parts(ptr as _, len as _)) | |||
// SAFETY: `ptr` is a valid pointer to a `NUL`-terminated C string. |
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.
Do we need to mention that this property (and the ones just below) is guaranteed by the /// # Safety
function prerequisite? Not sure how to formulate.
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.
Yeah, // SAFETY
comments should not just say "what", but "why" too, i.e. something like:
// SAFETY: `ptr` is a valid pointer to a `NUL`-terminated C string. | |
// SAFETY: The safety precondition guarantees `ptr` is a valid pointer to a `NUL`-terminated C string. |
rust/kernel/str.rs
Outdated
@@ -144,7 +149,8 @@ impl CStr { | |||
// requires `ptr_metadata`). | |||
// While none of them are current stable, it is very likely that one of | |||
// them will eventually be. | |||
&*(bytes as *const [u8] as *const Self) | |||
// SAFETY: property of `bytes` guaranteed by the caller. |
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.
Does this follow from /// # Safety
prerequisite above?
fn index(&self, index: ops::RangeFrom<usize>) -> &Self::Output { | ||
// Delegate bounds checking to slice. | ||
&self.as_bytes()[index.start..]; | ||
// Assign to _ to mute clippy's unnecessary operation warning. | ||
let _ = &self.as_bytes()[index.start..]; |
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.
Does this fix an unsafe warning?
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.
If it is for an unused variable warning, yeah, it should be in a separate commit and ideally a separate PR.
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.
Split into a separate commit. Little reluctant to split into a separate PR since I always feel such a simple change don't warrant its own merge commit ;)
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.
Yeah, in the future we will not have merge commits -- i.e. patches will be applied on top of each other in a linear fashion (when I add the sentient module to @ksquirrel :-)
Can be rebased now that #348 is in. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
E: Failed to fetch http://apt.llvm.org/focal/dists/llvm-toolchain-focal-12/main/binary-amd64/Packages File has unexpected size (9429 != 9436). Mirror sync in progress? [IP: 151.101.250.49 443] sigh |
That is |
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.
Nits since you have to push again thanks to LLVM ;)
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
No description provided.