Skip to content

Commit c87f106

Browse files
committed
update comments and some tweaks
1 parent cf93401 commit c87f106

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/helpers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
379379
_ => throw_unsup_format!("The {} error cannot be transformed into a raw os error", e)
380380
})?
381381
} else {
382-
// FIXME: we have to implement the windows' equivalent of this.
382+
// FIXME: we have to implement the Windows equivalent of this.
383383
throw_unsup_format!("Setting the last OS error from an io::Error is unsupported for {}.", target.target_os)
384384
};
385385
this.set_last_error(last_error)
@@ -390,7 +390,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
390390
/// `Ok(-1)` and sets the last OS error accordingly.
391391
///
392392
/// This function uses `T: From<i32>` instead of `i32` directly because some IO related
393-
/// functions return different integer types (like `read`, that returns an `i64`)
393+
/// functions return different integer types (like `read`, that returns an `i64`).
394394
fn try_unwrap_io_result<T: From<i32>>(
395395
&mut self,
396396
result: std::io::Result<T>,
@@ -423,11 +423,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
423423
) -> InterpResult<'tcx, bool> {
424424
let bytes = os_str_to_bytes(os_str)?;
425425
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
426-
// terminator to memory using the `ptr` pointer would cause an overflow.
426+
// terminator to memory using the `ptr` pointer would cause an out-of-bounds access.
427427
if size <= bytes.len() as u64 {
428428
return Ok(false);
429429
}
430-
// FIXME: We should use `Iterator::chain` instead when rust-lang/rust#65704 lands.
431430
self.eval_context_mut().memory.write_bytes(scalar, bytes.iter().copied().chain(iter::once(0u8)))?;
432431
Ok(true)
433432
}

src/operator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::convert::TryFrom;
2+
13
use rustc::ty::{Ty, layout::LayoutOf};
24
use rustc::mir;
35

@@ -117,8 +119,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
117119
pointee_ty: Ty<'tcx>,
118120
offset: i64,
119121
) -> InterpResult<'tcx, Scalar<Tag>> {
120-
// FIXME: assuming here that type size is less than `i64::max_value()`.
121-
let pointee_size = self.layout_of(pointee_ty)?.size.bytes() as i64;
122+
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
122123
let offset = offset
123124
.checked_mul(pointee_size)
124125
.ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?;

src/shims/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9595
throw_unsup_format!("unsupported flags {:#x}", flag & !mirror);
9696
}
9797

98-
let path: std::path::PathBuf = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?.into();
98+
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;
9999

100100
let fd = options.open(path).map(|file| {
101101
let mut fh = &mut this.machine.file_handler;

0 commit comments

Comments
 (0)