@@ -5,7 +5,7 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
5
5
use rustc:: mir;
6
6
use rustc:: ty:: {
7
7
self ,
8
- layout:: { self , Align , LayoutOf , Size , TyLayout } ,
8
+ layout:: { self , LayoutOf , Size , TyLayout } ,
9
9
} ;
10
10
11
11
use rand:: RngCore ;
@@ -95,13 +95,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
95
95
}
96
96
let this = self . eval_context_mut ( ) ;
97
97
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
-
105
98
let mut data = vec ! [ 0 ; len] ;
106
99
107
100
if this. machine . communicate {
@@ -114,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
114
107
rng. fill_bytes ( & mut data) ;
115
108
}
116
109
117
- this. memory . get_mut ( ptr . alloc_id ) ? . write_bytes ( & * this . tcx , ptr, & data)
110
+ this. memory . write_bytes ( ptr, data. iter ( ) . copied ( ) )
118
111
}
119
112
120
113
/// 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
420
413
421
414
/// Helper function to write an OsStr as a null-terminated sequence of bytes, which is what
422
415
/// 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 > {
424
417
let bytes = os_str_to_bytes ( os_str) ?;
425
- let len = bytes. len ( ) ;
426
418
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
427
419
// 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)
430
422
}
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 ( ) )
444
425
}
445
426
}
446
427
0 commit comments