@@ -519,26 +519,23 @@ JsonParseErrorType
519
519
json_lex (JsonLexContext * lex )
520
520
{
521
521
char * s ;
522
- int len ;
522
+ char * const end = lex -> input + lex -> input_length ;
523
523
JsonParseErrorType result ;
524
524
525
525
/* Skip leading whitespace. */
526
526
s = lex -> token_terminator ;
527
- len = s - lex -> input ;
528
- while (len < lex -> input_length &&
529
- (* s == ' ' || * s == '\t' || * s == '\n' || * s == '\r' ))
527
+ while (s < end && (* s == ' ' || * s == '\t' || * s == '\n' || * s == '\r' ))
530
528
{
531
529
if (* s ++ == '\n' )
532
530
{
533
531
++ lex -> line_number ;
534
532
lex -> line_start = s ;
535
533
}
536
- len ++ ;
537
534
}
538
535
lex -> token_start = s ;
539
536
540
537
/* Determine token type. */
541
- if (len >= lex -> input_length )
538
+ if (s >= end )
542
539
{
543
540
lex -> token_start = NULL ;
544
541
lex -> prev_token_terminator = lex -> token_terminator ;
@@ -623,7 +620,7 @@ json_lex(JsonLexContext *lex)
623
620
* the whole word as an unexpected token, rather than just
624
621
* some unintuitive prefix thereof.
625
622
*/
626
- for (p = s ; p - s < lex -> input_length - len && JSON_ALPHANUMERIC_CHAR (* p ); p ++ )
623
+ for (p = s ; p < end && JSON_ALPHANUMERIC_CHAR (* p ); p ++ )
627
624
/* skip */ ;
628
625
629
626
/*
@@ -672,21 +669,19 @@ static inline JsonParseErrorType
672
669
json_lex_string (JsonLexContext * lex )
673
670
{
674
671
char * s ;
675
- int len ;
672
+ char * const end = lex -> input + lex -> input_length ;
676
673
int hi_surrogate = -1 ;
677
674
678
675
if (lex -> strval != NULL )
679
676
resetStringInfo (lex -> strval );
680
677
681
678
Assert (lex -> input_length > 0 );
682
679
s = lex -> token_start ;
683
- len = lex -> token_start - lex -> input ;
684
680
for (;;)
685
681
{
686
682
s ++ ;
687
- len ++ ;
688
683
/* Premature end of the string. */
689
- if (len >= lex -> input_length )
684
+ if (s >= end )
690
685
{
691
686
lex -> token_terminator = s ;
692
687
return JSON_INVALID_TOKEN ;
@@ -704,8 +699,7 @@ json_lex_string(JsonLexContext *lex)
704
699
{
705
700
/* OK, we have an escape character. */
706
701
s ++ ;
707
- len ++ ;
708
- if (len >= lex -> input_length )
702
+ if (s >= end )
709
703
{
710
704
lex -> token_terminator = s ;
711
705
return JSON_INVALID_TOKEN ;
@@ -718,8 +712,7 @@ json_lex_string(JsonLexContext *lex)
718
712
for (i = 1 ; i <= 4 ; i ++ )
719
713
{
720
714
s ++ ;
721
- len ++ ;
722
- if (len >= lex -> input_length )
715
+ if (s >= end )
723
716
{
724
717
lex -> token_terminator = s ;
725
718
return JSON_INVALID_TOKEN ;
0 commit comments