@@ -98,10 +98,10 @@ mod value;
9898use std:: convert:: TryFrom ;
9999use std:: fmt;
100100use std:: io;
101+ use std:: io:: { Read , Write } ;
101102use std:: num:: NonZeroU32 ;
102103use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
103104
104- use byteorder:: { BigEndian , LittleEndian , ReadBytesExt , WriteBytesExt } ;
105105use rustc_ast:: LitKind ;
106106use rustc_data_structures:: fx:: FxHashMap ;
107107use rustc_data_structures:: sync:: { HashMapExt , Lock } ;
@@ -561,19 +561,33 @@ pub fn write_target_uint(
561561 mut target : & mut [ u8 ] ,
562562 data : u128 ,
563563) -> Result < ( ) , io:: Error > {
564- let len = target. len ( ) ;
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".
565566 match endianness {
566- Endian :: Little => target. write_uint128 :: < LittleEndian > ( data, len) ,
567- Endian :: Big => target. write_uint128 :: < BigEndian > ( data, len) ,
568- }
567+ Endian :: Little => target. write ( & data. to_le_bytes ( ) ) ?,
568+ Endian :: Big => target. write ( & data. to_be_bytes ( ) [ 16 - target. len ( ) ..] ) ?,
569+ } ;
570+ debug_assert ! ( target. len( ) == 0 ) ; // We should have filled the target buffer.
571+ Ok ( ( ) )
569572}
570573
571574#[ inline]
572575pub fn read_target_uint ( endianness : Endian , mut source : & [ u8 ] ) -> Result < u128 , io:: Error > {
573- match endianness {
574- Endian :: Little => source. read_uint128 :: < LittleEndian > ( source. len ( ) ) ,
575- Endian :: Big => source. read_uint128 :: < BigEndian > ( source. len ( ) ) ,
576- }
576+ // This u128 holds an "any-size uint" (since smaller uints can fits in it)
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".
579+ let uint = match endianness {
580+ Endian :: Little => {
581+ source. read ( & mut buf) ?;
582+ Ok ( u128:: from_le_bytes ( buf) )
583+ }
584+ Endian :: Big => {
585+ source. read ( & mut buf[ 16 - source. len ( ) ..] ) ?;
586+ Ok ( u128:: from_be_bytes ( buf) )
587+ }
588+ } ;
589+ debug_assert ! ( source. len( ) == 0 ) ; // We should have consumed the source buffer.
590+ uint
577591}
578592
579593////////////////////////////////////////////////////////////////////////////////
0 commit comments