@@ -380,7 +380,14 @@ impl<'de, R: Read<'de>> Deserializer<R> {
380
380
}
381
381
382
382
fn parse_integer ( & mut self , positive : bool ) -> Result < ParserNumber > {
383
- match try!( self . next_char_or_null ( ) ) {
383
+ let next = match try!( self . next_char ( ) ) {
384
+ Some ( b) => b,
385
+ None => {
386
+ return Err ( self . error ( ErrorCode :: EofWhileParsingValue ) ) ;
387
+ }
388
+ } ;
389
+
390
+ match next {
384
391
b'0' => {
385
392
// There can be only one leading '0'.
386
393
match try!( self . peek_or_null ( ) ) {
@@ -528,8 +535,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
528
535
_ => true ,
529
536
} ;
530
537
538
+ let next = match try!( self . next_char ( ) ) {
539
+ Some ( b) => b,
540
+ None => {
541
+ return Err ( self . error ( ErrorCode :: EofWhileParsingValue ) ) ;
542
+ }
543
+ } ;
544
+
531
545
// Make sure a digit follows the exponent place.
532
- let mut exp = match try! ( self . next_char_or_null ( ) ) {
546
+ let mut exp = match next {
533
547
c @ b'0' ...b'9' => ( c - b'0' ) as i32 ,
534
548
_ => {
535
549
return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
@@ -626,19 +640,19 @@ impl<'de, R: Read<'de>> Deserializer<R> {
626
640
}
627
641
628
642
#[ cfg( feature = "arbitrary_precision" ) ]
629
- fn scan_or_null ( & mut self , buf : & mut String ) -> Result < u8 > {
643
+ fn scan_or_eof ( & mut self , buf : & mut String ) -> Result < u8 > {
630
644
match try!( self . next_char ( ) ) {
631
645
Some ( b) => {
632
646
buf. push ( b as char ) ;
633
647
Ok ( b)
634
648
}
635
- None => Ok ( b'\x00' ) ,
649
+ None => Err ( self . error ( ErrorCode :: EofWhileParsingValue ) )
636
650
}
637
651
}
638
652
639
653
#[ cfg( feature = "arbitrary_precision" ) ]
640
654
fn scan_integer ( & mut self , buf : & mut String ) -> Result < ( ) > {
641
- match try!( self . scan_or_null ( buf) ) {
655
+ match try!( self . scan_or_eof ( buf) ) {
642
656
b'0' => {
643
657
// There can be only one leading '0'.
644
658
match try!( self . peek_or_null ( ) ) {
@@ -712,7 +726,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
712
726
}
713
727
714
728
// Make sure a digit follows the exponent place.
715
- match try!( self . scan_or_null ( buf) ) {
729
+ match try!( self . scan_or_eof ( buf) ) {
716
730
b'0' ...b'9' => { }
717
731
_ => {
718
732
return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
0 commit comments