diff --git a/src/helpers.rs b/src/helpers.rs index f7be3de8e481..dd0530cf48b4 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -379,7 +379,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx _ => throw_unsup_format!("The {} error cannot be transformed into a raw os error", e) })? } else { - // FIXME: we have to implement the windows' equivalent of this. + // FIXME: we have to implement the Windows equivalent of this. throw_unsup_format!("Setting the last OS error from an io::Error is unsupported for {}.", target.target_os) }; this.set_last_error(last_error) @@ -390,7 +390,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx /// `Ok(-1)` and sets the last OS error accordingly. /// /// This function uses `T: From` instead of `i32` directly because some IO related - /// functions return different integer types (like `read`, that returns an `i64`) + /// functions return different integer types (like `read`, that returns an `i64`). fn try_unwrap_io_result>( &mut self, result: std::io::Result, @@ -423,11 +423,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, bool> { let bytes = os_str_to_bytes(os_str)?; // If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null - // terminator to memory using the `ptr` pointer would cause an overflow. + // terminator to memory using the `ptr` pointer would cause an out-of-bounds access. if size <= bytes.len() as u64 { return Ok(false); } - // FIXME: We should use `Iterator::chain` instead when rust-lang/rust#65704 lands. self.eval_context_mut().memory.write_bytes(scalar, bytes.iter().copied().chain(iter::once(0u8)))?; Ok(true) } diff --git a/src/operator.rs b/src/operator.rs index 9c02c56fd6a1..a60bc8c0b13d 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -1,3 +1,5 @@ +use std::convert::TryFrom; + use rustc::ty::{Ty, layout::LayoutOf}; use rustc::mir; @@ -117,8 +119,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> { pointee_ty: Ty<'tcx>, offset: i64, ) -> InterpResult<'tcx, Scalar> { - // FIXME: assuming here that type size is less than `i64::max_value()`. - let pointee_size = self.layout_of(pointee_ty)?.size.bytes() as i64; + let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap(); let offset = offset .checked_mul(pointee_size) .ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?; diff --git a/src/shims/fs.rs b/src/shims/fs.rs index 08c9f3ec06e7..c484795d8fec 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -95,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx throw_unsup_format!("unsupported flags {:#x}", flag & !mirror); } - let path: std::path::PathBuf = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?.into(); + let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?; let fd = options.open(path).map(|file| { let mut fh = &mut this.machine.file_handler;