mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 21:47:15 +03:00
to_u64 and to_bytes are horribly easy to use wrongly.
This commit is contained in:
+4
-4
@@ -316,7 +316,7 @@ fn call_c_abi(
|
||||
|
||||
"memrchr" => {
|
||||
let ptr = self.into_ptr(args[0].value)?;
|
||||
let val = self.value_to_scalar(args[1])?.to_u64()? as u8;
|
||||
let val = self.value_to_scalar(args[1])?.to_bytes()? as u8;
|
||||
let num = self.value_to_scalar(args[2])?.to_u64()?;
|
||||
if let Some(idx) = self.memory.read_bytes(ptr, Size::from_bytes(num))?.iter().rev().position(
|
||||
|&c| c == val,
|
||||
@@ -331,7 +331,7 @@ fn call_c_abi(
|
||||
|
||||
"memchr" => {
|
||||
let ptr = self.into_ptr(args[0].value)?;
|
||||
let val = self.value_to_scalar(args[1])?.to_u64()? as u8;
|
||||
let val = self.value_to_scalar(args[1])?.to_bytes()? as u8;
|
||||
let num = self.value_to_scalar(args[2])?.to_u64()?;
|
||||
if let Some(idx) = self.memory.read_bytes(ptr, Size::from_bytes(num))?.iter().position(
|
||||
|&c| c == val,
|
||||
@@ -414,9 +414,9 @@ fn call_c_abi(
|
||||
}
|
||||
|
||||
"write" => {
|
||||
let fd = self.value_to_scalar(args[0])?.to_u64()?;
|
||||
let fd = self.value_to_scalar(args[0])?.to_bytes()?;
|
||||
let buf = self.into_ptr(args[1].value)?;
|
||||
let n = self.value_to_scalar(args[2])?.to_u64()?;
|
||||
let n = self.value_to_scalar(args[2])?.to_bytes()? as u64;
|
||||
trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
|
||||
let result = if fd == 1 || fd == 2 {
|
||||
// stdout/stderr
|
||||
|
||||
@@ -64,6 +64,9 @@ pub trait ScalarExt {
|
||||
fn from_f64(f: f64) -> Self;
|
||||
fn to_u64(self) -> EvalResult<'static, u64>;
|
||||
fn is_null(self) -> EvalResult<'static, bool>;
|
||||
/// HACK: this function just extracts all bits if `defined != 0`
|
||||
/// Mainly used for args of C-functions and we should totally correctly fetch the size
|
||||
/// of their arguments
|
||||
fn to_bytes(self) -> EvalResult<'static, u128>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user