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