update comments and some tweaks

This commit is contained in:
Ralf Jung
2019-10-24 10:23:44 +02:00
parent cf9340113e
commit c87f106cac
3 changed files with 7 additions and 7 deletions
+3 -4
View File
@@ -379,7 +379,7 @@ fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'t
_ => 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 @@ fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'t
/// `Ok(-1)` and sets the last OS error accordingly.
///
/// This function uses `T: From<i32>` 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<T: From<i32>>(
&mut self,
result: std::io::Result<T>,
@@ -423,11 +423,10 @@ fn write_os_str_to_c_string(
) -> 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)
}
+3 -2
View File
@@ -1,3 +1,5 @@
use std::convert::TryFrom;
use rustc::ty::{Ty, layout::LayoutOf};
use rustc::mir;
@@ -117,8 +119,7 @@ fn pointer_offset_inbounds(
pointee_ty: Ty<'tcx>,
offset: i64,
) -> InterpResult<'tcx, Scalar<Tag>> {
// 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)))?;
+1 -1
View File
@@ -95,7 +95,7 @@ fn open(
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;