diff options
author | Joseph Langley <mightyjo@gmail.com> | 2021-06-09 20:38:57 -0400 |
---|---|---|
committer | Joseph Langley <mightyjo@gmail.com> | 2021-06-09 21:46:01 -0400 |
commit | 988d379eb082423274381656863c804b00f82427 (patch) | |
tree | c97859f1711f9c6246dd60fdab42281a494d7cb1 /src/cpp-flex.skl | |
parent | 916636cb96a2334ca4c403f8ac293e202f72ca37 (diff) | |
download | flex-git-988d379eb082423274381656863c804b00f82427.tar.gz |
fix(skel): Add state buffer size handling to reentrant scanner skeletons.
Diffstat (limited to 'src/cpp-flex.skl')
-rwxr-xr-x | src/cpp-flex.skl | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index eefe106..fe9344f 100755 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -422,9 +422,11 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], m4_ifdef( [[M4_YY_NOT_IN_HEADER]], [[ -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the main buffer, + * plus the start state, plus the two end-of-buffer byte states. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_EXTRA_SPACE 3 +#define YY_STATE_BUF_SIZE (YY_BUF_SIZE + YY_STATE_BUF_EXTRA_SPACE) ]]) @@ -1227,6 +1229,7 @@ struct yyguts_t { m4_ifdef( [[M4_MODE_USES_REJECT]], [[ yy_state_type *yy_state_buf; yy_state_type *yy_state_ptr; + size_t yy_state_buf_max; char *yy_full_match; int yy_lp; @@ -2324,6 +2327,7 @@ void yyFlexLexer::ctor_common() { m4_ifdef( [[M4_MODE_USES_REJECT]], [[ yy_state_buf = new yy_state_type[YY_STATE_BUF_SIZE]; + yy_state_buf_max = YY_STATE_BUF_SIZE; ]], [[ yy_state_buf = 0; @@ -2842,7 +2846,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]], [[ */ if ( YY_G(yy_state_buf_max) < (yy_current_buffer()->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) { new_size = yy_current_buffer()->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE; - new_state_buf = (yy_state_type*) yyrealloc( YY_G(yy_state_buf), (new_size * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG ); + new_state_buf = (yy_state_type *)yyrealloc( YY_G(yy_state_buf), (new_size * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG ); if ( new_state_buf == NULL ) { YY_FATAL_ERROR( "out of dynamic memory in yylex()" ); @@ -2889,6 +2893,8 @@ void yyFlexLexer::yy_switch_to_buffer( yybuffer new_buffer ) ]]) { M4_YY_DECL_GUTS_VAR(); + size_t new_size = 0; + yy_state_type *new_state_buf = 0; /* TODO. We should be able to replace this entire function body * with @@ -2908,6 +2914,23 @@ void yyFlexLexer::yy_switch_to_buffer( yybuffer new_buffer ) YY_CURRENT_BUFFER_LVALUE = new_buffer; yy_load_buffer_state( M4_YY_CALL_ONLY_ARG ); + +m4_ifdef( [[M4_MODE_USES_REJECT]], [[ + /* Ensure the reject state buffer is large enough. + */ + if ( YY_G(yy_state_buf_max) < (YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) { + new_size = YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE; + new_state_buf = (yy_state_type *)yyrealloc( YY_G(yy_state_buf), (new_size * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG ); + + if ( new_state_buf == NULL ) { + YY_FATAL_ERROR( "out of dynamic memory in yylex()" ); + } + else { + YY_G(yy_state_buf) = new_state_buf; + YY_G(yy_state_buf_max) = new_size; + } + } +]] ) /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag @@ -3741,6 +3764,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]], [[ YY_G(yy_state_buf) = 0; YY_G(yy_state_ptr) = 0; + YY_G(yy_state_buf_max) = 0; YY_G(yy_full_match) = 0; YY_G(yy_lp) = 0; ]]) |