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(
560560 mut target : & mut [ u8 ] ,
561561 data : u128 ,
562562) -> 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".
563565 match endianness {
564566 Endian :: Little => target. write ( & data. to_le_bytes ( ) ) ?,
565567 Endian :: Big => target. write ( & data. to_be_bytes ( ) ) ?,
566568 } ;
569+ debug_assert ! ( target. len( ) == 0 ) ; // We should have filled the target buffer.
567570 Ok ( ( ) )
568571}
569572
570573#[ inline]
571574pub 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)
572576 let mut buf = [ 0u8 ; std:: mem:: size_of :: < u128 > ( ) ] ;
577+ // So we do not read exactly 16 bytes into the u128, just the "payload".
573578 source. read ( & mut buf) ?;
579+ debug_assert ! ( source. len( ) == 0 ) ; // We should have consumed the source buffer.
574580 match endianness {
575581 Endian :: Little => Ok ( u128:: from_le_bytes ( buf) ) ,
576582 Endian :: Big => Ok ( u128:: from_be_bytes ( buf) ) ,
You can’t perform that action at this time.
0 commit comments