@@ -918,11 +918,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
918
918
mut ptr : Pointer < Option < Provenance > > ,
919
919
size : Size ,
920
920
align : Align ,
921
- ) -> InterpResult < ' tcx , Size > {
921
+ ) -> InterpResult < ' tcx , u64 > {
922
922
let this = self . eval_context_ref ( ) ;
923
923
this. check_ptr_align ( ptr, align) ?;
924
924
925
- let mut len = Size :: ZERO ;
925
+ let mut len = 0 ;
926
926
loop {
927
927
// FIXME: We are re-getting the allocation each time around the loop.
928
928
// Would be nice if we could somehow "extend" an existing AllocRange.
@@ -931,25 +931,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
931
931
if c == 0 {
932
932
break ;
933
933
} else {
934
- len += Size :: from_bytes ( 1 ) ;
934
+ len += 1 ;
935
935
ptr = ptr. offset ( size, this) ?;
936
936
}
937
937
}
938
938
Ok ( len)
939
939
}
940
940
941
941
/// Calculates the length of a null terminated string of bytes.
942
- fn strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , Size > {
942
+ fn strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , u64 > {
943
943
self . generic_strlen ( ptr, Size :: from_bytes ( 1 ) , Align :: from_bytes ( 1 ) . unwrap ( ) )
944
944
}
945
945
946
946
/// Calculates the length of a null terminated string of u16.
947
- fn u16_strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , Size > {
947
+ fn u16_strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , u64 > {
948
948
self . generic_strlen ( ptr, Size :: from_bytes ( 2 ) , Align :: from_bytes ( 2 ) . unwrap ( ) )
949
949
}
950
950
951
951
/// Calculates the length of a null terminated string of wchar_t.
952
- fn wchar_t_strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , Size > {
952
+ fn wchar_t_strlen ( & self , ptr : Pointer < Option < Provenance > > ) -> InterpResult < ' tcx , u64 > {
953
953
let this = self . eval_context_ref ( ) ;
954
954
let wchar_t = this. libc_ty_layout ( "wchar_t" ) ;
955
955
self . generic_strlen ( ptr, wchar_t. size , wchar_t. align . abi )
@@ -976,7 +976,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
976
976
' mir : ' a ,
977
977
{
978
978
let this = self . eval_context_ref ( ) ;
979
- let len = this. strlen ( ptr) ?;
979
+ let len = Size :: from_bytes ( this. strlen ( ptr) ?) ;
980
980
this. read_bytes_ptr_strip_provenance ( ptr, len)
981
981
}
982
982
@@ -1014,8 +1014,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1014
1014
{
1015
1015
let this = self . eval_context_ref ( ) ;
1016
1016
let len = this. u16_strlen ( ptr) ?;
1017
- let bytes = this. read_bytes_ptr_strip_provenance ( ptr, len) ?;
1018
- unsafe { Ok ( bytes. align_to :: < u16 > ( ) . 1 ) }
1017
+ let bytes = this. read_bytes_ptr_strip_provenance ( ptr, Size :: from_bytes ( 2 * len) ) ?;
1018
+ unsafe {
1019
+ Ok ( std:: slice:: from_raw_parts ( bytes. as_ptr ( ) . cast :: < u16 > ( ) , len. try_into ( ) . unwrap ( ) ) )
1020
+ }
1019
1021
}
1020
1022
1021
1023
/// Helper function to write a sequence of u16 with an added 0x0000-terminator, which is what
0 commit comments