@@ -55,13 +55,14 @@ impl IndexedVal for AllocId {
55
55
/// Utility function used to read an allocation data into a unassigned integer.
56
56
pub ( crate ) fn read_target_uint ( mut bytes : & [ u8 ] ) -> Result < u128 , Error > {
57
57
let mut buf = [ 0u8 ; std:: mem:: size_of :: < u128 > ( ) ] ;
58
+ let start_position = 16 - bytes. len ( ) ;
58
59
match MachineInfo :: target_endianess ( ) {
59
60
Endian :: Little => {
60
- let _ = bytes. read ( & mut buf) ?;
61
+ bytes. read_exact ( & mut buf[ ..start_position ] ) ?;
61
62
Ok ( u128:: from_le_bytes ( buf) )
62
63
}
63
64
Endian :: Big => {
64
- bytes. read_exact ( & mut buf[ 16 - bytes . len ( ) ..] ) ?;
65
+ bytes. read_exact ( & mut buf[ start_position ..] ) ?;
65
66
Ok ( u128:: from_be_bytes ( buf) )
66
67
}
67
68
}
@@ -70,13 +71,14 @@ pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {
70
71
/// Utility function used to read an allocation data into an assigned integer.
71
72
pub ( crate ) fn read_target_int ( mut bytes : & [ u8 ] ) -> Result < i128 , Error > {
72
73
let mut buf = [ 0u8 ; std:: mem:: size_of :: < i128 > ( ) ] ;
74
+ let start_position = 16 - bytes. len ( ) ;
73
75
match MachineInfo :: target_endianess ( ) {
74
76
Endian :: Little => {
75
- let _ = bytes. read ( & mut buf) ?;
77
+ bytes. read_exact ( & mut buf[ ..start_position ] ) ?;
76
78
Ok ( i128:: from_le_bytes ( buf) )
77
79
}
78
80
Endian :: Big => {
79
- bytes. read_exact ( & mut buf[ 16 - bytes . len ( ) ..] ) ?;
81
+ bytes. read_exact ( & mut buf[ start_position ..] ) ?;
80
82
Ok ( i128:: from_be_bytes ( buf) )
81
83
}
82
84
}
0 commit comments