2626//or it's the macro PARSING (1 currently but could be any invalid non-NULL pointer) which means we're parsing
2727token_lex read_token (FILE * file , lexer_state * lex_state , FILE * preprocessed )
2828{
29- static char token_buf [MAX_TOKEN_LEN ];
29+ static char token_buf [MAX_TOKEN_LEN + 1 ];
3030int c , i = 0 , tmp ;
3131
3232token_lex tok_lex = { 0 };
@@ -289,12 +289,12 @@ token_lex read_token(FILE* file, lexer_state* lex_state, FILE* preprocessed)
289289token_buf [i ++ ] = c ;
290290HANDLE_BACKSLASH ();
291291
292- if (i == MAX_TOKEN_LEN - 1 )
292+ if (i > MAX_TOKEN_LEN )
293293goto token_length_error ;
294294}
295295
296296if (c == '.' ) {
297- if (i == MAX_TOKEN_LEN - 1 )
297+ if (i > MAX_TOKEN_LEN )
298298goto token_length_error ;
299299
300300token_buf [i ++ ] = c ;
@@ -304,7 +304,7 @@ token_lex read_token(FILE* file, lexer_state* lex_state, FILE* preprocessed)
304304token_buf [i ++ ] = c ;
305305HANDLE_BACKSLASH ();
306306
307- if (i == MAX_TOKEN_LEN - 1 )
307+ if (i > MAX_TOKEN_LEN )
308308goto token_length_error ;
309309}
310310
@@ -327,7 +327,7 @@ token_lex read_token(FILE* file, lexer_state* lex_state, FILE* preprocessed)
327327token_buf [i ++ ] = c ;
328328HANDLE_BACKSLASH ();
329329
330- if (i == MAX_TOKEN_LEN - 1 )
330+ if (i > MAX_TOKEN_LEN )
331331goto token_length_error ;
332332}
333333ungetc (c , file );
@@ -373,7 +373,7 @@ token_lex read_token(FILE* file, lexer_state* lex_state, FILE* preprocessed)
373373while (c != '"' ) {
374374token_buf [i ++ ] = c ;
375375HANDLE_BACKSLASH ();
376- if (i == MAX_TOKEN_LEN - 1 )
376+ if (i > MAX_TOKEN_LEN )
377377goto token_length_error ;
378378}
379379token_buf [i ] = '\0' ;
@@ -401,10 +401,10 @@ token_lex read_token(FILE* file, lexer_state* lex_state, FILE* preprocessed)
401401return tok_lex ;
402402
403403stray_backslash :
404- lex_error (lex_state , "stray \\ in program (perhaps you have a space between it and a newline)" );
404+ lex_error (lex_state , "stray \\ in program (perhaps you have a space between it and a newline)\n " );
405405
406406token_length_error :
407- lex_error (lex_state , "Token length is too long, max token length is %d, " , MAX_TOKEN_LEN - 1 );
407+ lex_error (lex_state , "Token length is too long, max token length is %d\n " , MAX_TOKEN_LEN );
408408
409409// never gets here, gets rid of compiler warning
410410return tok_lex ;
@@ -440,7 +440,7 @@ do { \
440440
441441token_lex read_token_from_str (char * input , lexer_state * lex_state , FILE * preprocessed )
442442{
443- static char token_buf [MAX_TOKEN_LEN ];
443+ static char token_buf [MAX_TOKEN_LEN + 1 ];
444444int i = 0 , tmp ;
445445
446446token_lex tok_lex = { 0 };
@@ -704,12 +704,12 @@ token_lex read_token_from_str(char* input, lexer_state* lex_state, FILE* preproc
704704token_buf [i ++ ] = * c ;
705705HANDLE_BACKSLASH_STR ();
706706
707- if (i == MAX_TOKEN_LEN - 1 )
707+ if (i > MAX_TOKEN_LEN )
708708goto token_length_error ;
709709}
710710
711711if (* c == '.' ) {
712- if (i == MAX_TOKEN_LEN - 1 )
712+ if (i > MAX_TOKEN_LEN )
713713goto token_length_error ;
714714
715715token_buf [i ++ ] = * c ;
@@ -719,7 +719,7 @@ token_lex read_token_from_str(char* input, lexer_state* lex_state, FILE* preproc
719719token_buf [i ++ ] = * c ;
720720HANDLE_BACKSLASH_STR ();
721721
722- if (i == MAX_TOKEN_LEN - 1 )
722+ if (i > MAX_TOKEN_LEN )
723723goto token_length_error ;
724724}
725725
@@ -742,7 +742,7 @@ token_lex read_token_from_str(char* input, lexer_state* lex_state, FILE* preproc
742742token_buf [i ++ ] = * c ;
743743HANDLE_BACKSLASH_STR ();
744744
745- if (i == MAX_TOKEN_LEN - 1 )
745+ if (i > MAX_TOKEN_LEN )
746746goto token_length_error ;
747747}
748748-- c ;
@@ -785,7 +785,7 @@ token_lex read_token_from_str(char* input, lexer_state* lex_state, FILE* preproc
785785while (* c != '"' ) {
786786token_buf [i ++ ] = * c ;
787787HANDLE_BACKSLASH_STR ();
788- if (i == MAX_TOKEN_LEN - 1 )
788+ if (i > MAX_TOKEN_LEN )
789789goto token_length_error ;
790790}
791791token_buf [i ] = '\0' ;
@@ -816,10 +816,10 @@ token_lex read_token_from_str(char* input, lexer_state* lex_state, FILE* preproc
816816return tok_lex ;
817817
818818stray_backslash :
819- lex_error (lex_state , "stray \\ in program (perhaps you have a space between it and a newline)" );
819+ lex_error (lex_state , "stray \\ in program (perhaps you have a space between it and a newline)\n " );
820820
821821token_length_error :
822- lex_error (lex_state , "Token length is too long, max token length is %d, " , MAX_TOKEN_LEN - 1 );
822+ lex_error (lex_state , "Token length is too long, max token length is %d\n " , MAX_TOKEN_LEN );
823823
824824// never gets here, gets rid of compiler warning
825825return tok_lex ;
0 commit comments