@@ -17,28 +17,13 @@ pub enum PathConversion {
1717 TargetToHost ,
1818}
1919
20- #[ cfg( unix) ]
21- pub fn os_str_to_bytes < ' tcx > ( os_str : & OsStr ) -> InterpResult < ' tcx , & [ u8 ] > {
22- Ok ( os_str. as_bytes ( ) )
23- }
24-
25- #[ cfg( not( unix) ) ]
26- pub fn os_str_to_bytes < ' tcx > ( os_str : & OsStr ) -> InterpResult < ' tcx , & [ u8 ] > {
27- // On non-unix platforms the best we can do to transform bytes from/to OS strings is to do the
28- // intermediate transformation into strings. Which invalidates non-utf8 paths that are actually
29- // valid.
30- os_str
31- . to_str ( )
32- . map ( |s| s. as_bytes ( ) )
33- . ok_or_else ( || err_unsup_format ! ( "{:?} is not a valid utf-8 string" , os_str) . into ( ) )
34- }
35-
3620#[ cfg( unix) ]
3721pub fn bytes_to_os_str < ' tcx > ( bytes : & [ u8 ] ) -> InterpResult < ' tcx , & OsStr > {
3822 Ok ( OsStr :: from_bytes ( bytes) )
3923}
4024#[ cfg( not( unix) ) ]
4125pub fn bytes_to_os_str < ' tcx > ( bytes : & [ u8 ] ) -> InterpResult < ' tcx , & OsStr > {
26+ // We cannot use `from_os_str_bytes_unchecked` here since we can't trust `bytes`.
4227 let s = std:: str:: from_utf8 ( bytes)
4328 . map_err ( |_| err_unsup_format ! ( "{:?} is not a valid utf-8 string" , bytes) ) ?;
4429 Ok ( OsStr :: new ( s) )
@@ -97,7 +82,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9782 ptr : Pointer < Option < Provenance > > ,
9883 size : u64 ,
9984 ) -> InterpResult < ' tcx , ( bool , u64 ) > {
100- let bytes = os_str_to_bytes ( os_str) ? ;
85+ let bytes = os_str. as_os_str_bytes ( ) ;
10186 self . eval_context_mut ( ) . write_c_str ( bytes, ptr, size)
10287 }
10388
0 commit comments