File tree 1 file changed +6
-0
lines changed
compiler/rustc_middle/src/mir/interpret
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -561,17 +561,23 @@ pub fn write_target_uint(
561
561
mut target : & mut [ u8 ] ,
562
562
data : u128 ,
563
563
) -> Result < ( ) , io:: Error > {
564
+ // This u128 holds an "any-size uint" (since smaller uints can fits in it)
565
+ // So we do not write all bytes of the u128, just the "payload".
564
566
match endianness {
565
567
Endian :: Little => target. write ( & data. to_le_bytes ( ) ) ?,
566
568
Endian :: Big => target. write ( & data. to_be_bytes ( ) ) ?,
567
569
} ;
570
+ debug_assert ! ( target. len( ) == 0 ) ; // We should have filled the target buffer.
568
571
Ok ( ( ) )
569
572
}
570
573
571
574
#[ inline]
572
575
pub fn read_target_uint ( endianness : Endian , mut source : & [ u8 ] ) -> Result < u128 , io:: Error > {
576
+ // This u128 holds an "any-size uint" (since smaller uints can fits in it)
573
577
let mut buf = [ 0u8 ; std:: mem:: size_of :: < u128 > ( ) ] ;
578
+ // So we do not read exactly 16 bytes into the u128, just the "payload".
574
579
source. read ( & mut buf) ?;
580
+ debug_assert ! ( source. len( ) == 0 ) ; // We should have consumed the source buffer.
575
581
match endianness {
576
582
Endian :: Little => Ok ( u128:: from_le_bytes ( buf) ) ,
577
583
Endian :: Big => Ok ( u128:: from_be_bytes ( buf) ) ,
You can’t perform that action at this time.
0 commit comments