@@ -380,7 +380,14 @@ impl<'de, R: Read<'de>> Deserializer<R> {
380380 }
381381
382382 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 {
384391 b'0' => {
385392 // There can be only one leading '0'.
386393 match try!( self . peek_or_null ( ) ) {
@@ -496,7 +503,10 @@ impl<'de, R: Read<'de>> Deserializer<R> {
496503 }
497504
498505 if !at_least_one_digit {
499- return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ;
506+ match try!( self . peek ( ) ) {
507+ Some ( _) => return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ,
508+ None => return Err ( self . peek_error ( ErrorCode :: EofWhileParsingValue ) ) ,
509+ }
500510 }
501511
502512 match try!( self . peek_or_null ( ) ) {
@@ -525,8 +535,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
525535 _ => true ,
526536 } ;
527537
538+ let next = match try!( self . next_char ( ) ) {
539+ Some ( b) => b,
540+ None => {
541+ return Err ( self . error ( ErrorCode :: EofWhileParsingValue ) ) ;
542+ }
543+ } ;
544+
528545 // Make sure a digit follows the exponent place.
529- let mut exp = match try! ( self . next_char_or_null ( ) ) {
546+ let mut exp = match next {
530547 c @ b'0' ...b'9' => ( c - b'0' ) as i32 ,
531548 _ => {
532549 return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
@@ -623,19 +640,19 @@ impl<'de, R: Read<'de>> Deserializer<R> {
623640 }
624641
625642 #[ cfg( feature = "arbitrary_precision" ) ]
626- fn scan_or_null ( & mut self , buf : & mut String ) -> Result < u8 > {
643+ fn scan_or_eof ( & mut self , buf : & mut String ) -> Result < u8 > {
627644 match try!( self . next_char ( ) ) {
628645 Some ( b) => {
629646 buf. push ( b as char ) ;
630647 Ok ( b)
631648 }
632- None => Ok ( b'\x00' ) ,
649+ None => Err ( self . error ( ErrorCode :: EofWhileParsingValue ) )
633650 }
634651 }
635652
636653 #[ cfg( feature = "arbitrary_precision" ) ]
637654 fn scan_integer ( & mut self , buf : & mut String ) -> Result < ( ) > {
638- match try!( self . scan_or_null ( buf) ) {
655+ match try!( self . scan_or_eof ( buf) ) {
639656 b'0' => {
640657 // There can be only one leading '0'.
641658 match try!( self . peek_or_null ( ) ) {
@@ -680,7 +697,10 @@ impl<'de, R: Read<'de>> Deserializer<R> {
680697 }
681698
682699 if !at_least_one_digit {
683- return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ;
700+ match try!( self . peek ( ) ) {
701+ Some ( _) => return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ,
702+ None => return Err ( self . peek_error ( ErrorCode :: EofWhileParsingValue ) ) ,
703+ }
684704 }
685705
686706 match try!( self . peek_or_null ( ) ) {
@@ -706,7 +726,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
706726 }
707727
708728 // Make sure a digit follows the exponent place.
709- match try!( self . scan_or_null ( buf) ) {
729+ match try!( self . scan_or_eof ( buf) ) {
710730 b'0' ...b'9' => { }
711731 _ => {
712732 return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
0 commit comments