Skip to content

Commit

Permalink
fix clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
el-ev committed Feb 27, 2025
1 parent 989c19b commit c730084
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,9 +1668,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn chmod(&mut self, path_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`chmod`", reject_with)?;
Expand All @@ -1682,6 +1679,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
{
use std::os::unix::fs::PermissionsExt;

let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

let result = std::fs::set_permissions(
pathname,
Permissions::from_mode(perm.try_into().unwrap()),
Expand All @@ -1699,20 +1699,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn fchmod(&mut self, fd_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let fd = this.read_scalar(fd_op)?.to_i32()?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`fchmod`", reject_with)?;
// Set error code as "EBADF" (bad fd)
return this.set_last_error_and_return_i32(LibcError("EBADF"));
}

// `Permissions::from_mode` is Unix-specific.
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;

let fd = this.read_scalar(fd_op)?.to_i32()?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

let Some(fd) = this.machine.fds.get(fd) else {
return this.set_last_error_and_return_i32(LibcError("EBADF"));
};
Expand Down

0 comments on commit c730084

Please sign in to comment.