@@ -1738,7 +1738,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1738
1738
// Get the raw bytes from the template. This is passed to us from `std` as an `OsString`.
1739
1739
// These bytes represent a string in _target_ OS encoding, which may or may not match
1740
1740
// the _host_ OS encoding.
1741
- let template_bytes = this. eval_context_ref ( ) . read_c_str ( this. read_pointer ( template_op) ?) ?;
1741
+ let template_ptr = this. read_pointer ( template_op) ?;
1742
+ let mut template = this. eval_context_ref ( ) . read_c_str ( template_ptr) ?. to_owned ( ) ;
1743
+ let template_bytes = template. as_mut_slice ( ) ;
1742
1744
1743
1745
// Reject if isolation is enabled.
1744
1746
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
@@ -1804,13 +1806,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1804
1806
// Generate a random unique suffix.
1805
1807
let unique_suffix = SUBSTITUTIONS . choose_multiple ( & mut rng, 6 ) . collect :: < String > ( ) ;
1806
1808
1807
- // The passed in template encoding may or may not match the host.
1808
- let mut base = bytes_to_os_str ( & template_bytes[ ..start_pos] ) ?. to_os_string ( ) ;
1809
+ // Replace the template string with the random string.
1810
+ template_bytes[ start_pos..end_pos] . copy_from_slice ( unique_suffix. as_bytes ( ) ) ;
1811
+
1812
+ // Write the modified template back to the passed in pointer to maintain POSIX semantics.
1813
+ this. write_bytes_ptr ( template_ptr, template_bytes. to_owned ( ) ) ?;
1809
1814
1810
- // Add the randomly generated suffix to the given static prefix .
1811
- base . push ( unique_suffix ) ;
1815
+ // The passed in template encoding may or may not match the host .
1816
+ let p = bytes_to_os_str ( template_bytes ) ? . to_os_string ( ) ;
1812
1817
1813
- let possibly_unique = std:: env:: temp_dir ( ) . join :: < PathBuf > ( base . into ( ) ) ;
1818
+ let possibly_unique = std:: env:: temp_dir ( ) . join :: < PathBuf > ( p . into ( ) ) ;
1814
1819
1815
1820
let file = fopts. open ( & possibly_unique) ;
1816
1821
0 commit comments