-
Notifications
You must be signed in to change notification settings - Fork 677
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
Use Wrapping for intended underflow of unsigned integer value. #369
Conversation
@@ -111,11 +111,15 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> { | |||
Errno::result(res).map(drop) | |||
} | |||
|
|||
|
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.
Any reason for adding these 2 lines?
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.
No. I'll fix it.
I readded the (reworded) comment. |
use std::num::Wrapping; | ||
unsafe { libc::chown(cstr.as_ptr(), | ||
owner.unwrap_or((Wrapping(0 as uid_t) - Wrapping(1 as uid_t)).0), | ||
group.unwrap_or((Wrapping(0 as gid_t) - Wrapping(1 as gid_t)).0)) } |
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.
one last nit, can we use 0.wrapping_sub(1)
instead of using Wrapping
? I think it'll be easier to read and doesn't require an extra import.
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.
Certainly! If I had known the function, I would have used it right away.
Use Wrapping for intended underflow of unsigned integer value. This fixes an warning made error on nightly builds.
☀️ Test successful - status |
This fixes an warning made error on nightly builds.