From 50be5a83c50528cc61d2b65a73839dbb25fc9c67 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 1 Oct 2019 09:18:55 -0500 Subject: [PATCH] Remove return argument when fd is not found --- src/shims/io.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/shims/io.rs b/src/shims/io.rs index 0cb2d7eeeab..c91d3a07726 100644 --- a/src/shims/io.rs +++ b/src/shims/io.rs @@ -50,16 +50,15 @@ fn open( .memory() .read_c_str(this.read_scalar(path_op)?.not_undef()?)?; let path = std::str::from_utf8(path_bytes) - .map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))? - .to_owned(); - let fd = File::open(&path).map(|file| { + .map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?; + let fd = File::open(path).map(|file| { let mut fh = &mut this.machine.file_handler; fh.low += 1; fh.handles.insert(fh.low, FileHandle { file, flag }); fh.low }); - this.consume_result::(fd, -1) + this.consume_result(fd) } fn fcntl( @@ -94,7 +93,7 @@ fn fcntl( } Ok(0) } else if cmd == this.eval_libc_i32("F_GETFD")? { - this.get_handle_and(fd, |handle| Ok(handle.flag), -1) + this.get_handle_and(fd, |handle| Ok(handle.flag)) } else { throw_unsup_format!("Unsupported command {:#x}", cmd); } @@ -111,8 +110,7 @@ fn close(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { this.remove_handle_and( fd, - |handle, this| this.consume_result::(handle.file.sync_all().map(|_| 0), -1), - -1, + |handle, this| this.consume_result(handle.file.sync_all().map(|_| 0i32)), ) } @@ -148,13 +146,12 @@ fn read( .map(|bytes| bytes as i64); // Reinsert the file handle this.machine.file_handler.handles.insert(fd, handle); - this.consume_result::(bytes, -1) + this.consume_result(bytes) }, - -1, ) } - fn get_handle_and(&mut self, fd: i32, f: F, t: T) -> InterpResult<'tcx, T> + fn get_handle_and>(&mut self, fd: i32, f: F) -> InterpResult<'tcx, T> where F: Fn(&FileHandle) -> InterpResult<'tcx, T>, { @@ -163,11 +160,11 @@ fn get_handle_and(&mut self, fd: i32, f: F, t: T) -> InterpResult<'tcx, T> f(handle) } else { this.machine.last_error = this.eval_libc_i32("EBADF")? as u32; - Ok(t) + Ok((-1).into()) } } - fn remove_handle_and(&mut self, fd: i32, mut f: F, t: T) -> InterpResult<'tcx, T> + fn remove_handle_and>(&mut self, fd: i32, mut f: F) -> InterpResult<'tcx, T> where F: FnMut(FileHandle, &mut MiriEvalContext<'mir, 'tcx>) -> InterpResult<'tcx, T>, { @@ -176,16 +173,16 @@ fn remove_handle_and(&mut self, fd: i32, mut f: F, t: T) -> InterpResult<' f(handle, this) } else { this.machine.last_error = this.eval_libc_i32("EBADF")? as u32; - Ok(t) + Ok((-1).into()) } } - fn consume_result(&mut self, result: std::io::Result, t: T) -> InterpResult<'tcx, T> { + fn consume_result>(&mut self, result: std::io::Result) -> InterpResult<'tcx, T> { match result { Ok(ok) => Ok(ok), Err(e) => { self.eval_context_mut().machine.last_error = e.raw_os_error().unwrap() as u32; - Ok(t) + Ok((-1).into()) } } } -- 2.44.0