@@ -5,7 +5,7 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
55use rustc:: mir;
66use rustc:: ty:: {
77 self ,
8- layout:: { self , Align , LayoutOf , Size , TyLayout } ,
8+ layout:: { self , LayoutOf , Size , TyLayout } ,
99} ;
1010
1111use rand:: RngCore ;
@@ -95,13 +95,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9595 }
9696 let this = self . eval_context_mut ( ) ;
9797
98- // Don't forget the bounds check.
99- let ptr = this. memory . check_ptr_access (
100- ptr,
101- Size :: from_bytes ( len as u64 ) ,
102- Align :: from_bytes ( 1 ) . unwrap ( )
103- ) ?. expect ( "we already checked for size 0" ) ;
104-
10598 let mut data = vec ! [ 0 ; len] ;
10699
107100 if this. machine . communicate {
@@ -114,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
114107 rng. fill_bytes ( & mut data) ;
115108 }
116109
117- this. memory . get_mut ( ptr . alloc_id ) ? . write_bytes ( & * this . tcx , ptr, & data)
110+ this. memory . write_bytes ( ptr, data. iter ( ) . copied ( ) )
118111 }
119112
120113 /// Visits the memory covered by `place`, sensitive to freezing: the 3rd parameter
@@ -420,27 +413,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
420413
421414 /// Helper function to write an OsStr as a null-terminated sequence of bytes, which is what
422415 /// the Unix APIs usually handle.
423- fn write_os_str_to_c_string ( & mut self , os_str : & OsStr , ptr : Pointer < Tag > , size : u64 ) -> InterpResult < ' tcx > {
416+ fn write_os_str_to_c_string ( & mut self , os_str : & OsStr , scalar : Scalar < Tag > , size : u64 ) -> InterpResult < ' tcx > {
424417 let bytes = os_str_to_bytes ( os_str) ?;
425- let len = bytes. len ( ) ;
426418 // If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
427419 // terminator to memory using the `ptr` pointer would cause an overflow.
428- if size <= len as u64 {
429- throw_unsup_format ! ( "OsString of length {} is too large for destination buffer of size {}" , len, size)
420+ if size <= bytes . len ( ) as u64 {
421+ throw_unsup_format ! ( "OsString of length {} is too large for destination buffer of size {}" , bytes . len( ) , size)
430422 }
431- let actual_len = ( len as u64 )
432- . checked_add ( 1 )
433- . map ( Size :: from_bytes)
434- . ok_or_else ( || err_unsup_format ! ( "OsString of length {} is too large" , len) ) ?;
435- let this = self . eval_context_mut ( ) ;
436- this. memory . check_ptr_access ( ptr. into ( ) , actual_len, Align :: from_bytes ( 1 ) . unwrap ( ) ) ?;
437- let buffer = this. memory . get_mut ( ptr. alloc_id ) ?. get_bytes_mut ( & * this. tcx , ptr, actual_len) ?;
438- buffer[ ..len] . copy_from_slice ( bytes) ;
439- // This is ok because the buffer was strictly larger than `bytes`, so after adding the
440- // null terminator, the buffer size is larger or equal to `bytes.len()`, meaning that
441- // `bytes` actually fit inside tbe buffer.
442- buffer[ len] = 0 ;
443- Ok ( ( ) )
423+ // FIXME: We should use `Iterator::chain` instead when rust-lang/rust#65704 lands.
424+ self . eval_context_mut ( ) . memory . write_bytes ( scalar, [ bytes, & [ 0 ] ] . concat ( ) )
444425 }
445426}
446427
0 commit comments