Skip to content

Commit

Permalink
Auto merge of #369 - fiveop:fixoverflow, r=kamalmarhubi
Browse files Browse the repository at this point in the history
Use Wrapping for intended underflow of unsigned integer value.

This fixes an warning made error on nightly builds.
  • Loading branch information
homu committed May 6, 2016
2 parents e8ebc95 + 2139c90 commit 7931e48
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
#[inline]
pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<uid_t>, group: Option<gid_t>) -> Result<()> {
let res = try!(path.with_nix_path(|cstr| {
// We use `0 - 1` to get `-1 : {u,g}id_t` which is specified as the no-op value for chown(3).
unsafe { libc::chown(cstr.as_ptr(), owner.unwrap_or(0 - 1), group.unwrap_or(0 - 1)) }
// According to the POSIX specification, -1 is used to indicate that
// owner and group, respectively, are not to be changed. Since uid_t and
// gid_t are unsigned types, we use wrapping_sub to get '-1'.
unsafe { libc::chown(cstr.as_ptr(),
owner.unwrap_or((0 as uid_t).wrapping_sub(1)),
group.unwrap_or((0 as gid_t).wrapping_sub(1))) }
}));

Errno::result(res).map(drop)
Expand Down

0 comments on commit 7931e48

Please sign in to comment.