]> git.lizzy.rs Git - rust.git/commitdiff
precise getrandom return type and align_offset arithmetic
authorRalf Jung <post@ralfj.de>
Sat, 28 Mar 2020 16:47:00 +0000 (17:47 +0100)
committerRalf Jung <post@ralfj.de>
Sat, 28 Mar 2020 16:47:00 +0000 (17:47 +0100)
src/shims/foreign_items/posix/linux.rs
src/shims/mod.rs

index d11d355eb3461f60a9734101db241683c0842a4b..f56d5b3959c75c621cdf27b0cc7de84a438c1b9a 100644 (file)
@@ -140,6 +140,6 @@ fn getrandom<'tcx>(
     let _flags = this.read_scalar(args[2])?.to_i32()?;
 
     this.gen_random(ptr, len)?;
-    this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
+    this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;
     Ok(())
 }
index 588f496d1f3ffb449570f5fffab225fcfd9be0cf..58972731fb1d8bc511b5f510d546000c194f80c3 100644 (file)
@@ -75,7 +75,7 @@ fn align_offset(
         let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
 
         // Default: no result.
-        let mut result = this.truncate(u128::MAX, dest.layout);
+        let mut result = this.usize_max();
         if let Ok(ptr) = this.force_ptr(ptr_scalar) {
             // Only do anything if we can identify the allocation this goes to.
             let cur_align =
@@ -84,7 +84,7 @@ fn align_offset(
                 // If the allocation alignment is at least the required alignment we use the
                 // libcore implementation.
                 // FIXME: is this correct in case of truncation?
-                result = u128::try_from(
+                result = u64::try_from(
                     (this.force_bits(ptr_scalar, this.pointer_size())? as *const i8)
                         .align_offset(usize::try_from(req_align).unwrap())
                 ).unwrap();
@@ -92,7 +92,7 @@ fn align_offset(
         }
 
         // Return result, and jump to caller.
-        this.write_scalar(Scalar::from_uint(result, this.pointer_size()), dest)?;
+        this.write_scalar(Scalar::from_machine_usize(result, this), dest)?;
         this.go_to_block(ret);
         Ok(())
     }