diff options
author | Joseph Langley <mightyjo@gmail.com> | 2022-05-16 20:07:33 -0400 |
---|---|---|
committer | Joseph Langley <mightyjo@gmail.com> | 2022-05-18 11:15:49 -0400 |
commit | 4581eccf1e9cb5c2b0646854a5b5b2024c4b602b (patch) | |
tree | d01afe4db5c2ad3b0a1f636006b78915de1e1a98 | |
parent | 9d9a039c31d1159fca492bf770403deef4c05cd2 (diff) | |
download | flex-git-4581eccf1e9cb5c2b0646854a5b5b2024c4b602b.tar.gz |
fix(issue-525): Fail gracefully when yy_get_next_buffer can't find one.
Demonstrate yyinput() error checking for this condition.
-rw-r--r-- | src/c99-flex.skl | 6 | ||||
-rw-r--r-- | src/cpp-flex.skl | 12 | ||||
-rw-r--r-- | src/go-flex.skl | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/Makefile.am | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/yywrap_r.i3.l | 0 |
5 files changed, 21 insertions, 3 deletions
diff --git a/src/c99-flex.skl b/src/c99-flex.skl index 796fe11..ca712dd 100644 --- a/src/c99-flex.skl +++ b/src/c99-flex.skl @@ -712,7 +712,11 @@ static void yy_init_buffer(yybuffer b, FILE * file, yyscan_t yyscanner) yy_flush_buffer( b, yyscanner); b->yy_input_file = file; - b->yy_fill_buffer = true; + if (b->yy_input_file == NULL) { + b->yy_fill_buffer = false; + } else { + b->yy_fill_buffer = true; + } /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index 5af5003..32bedfc 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -3060,7 +3060,17 @@ m4_ifdef([[M4_MODE_C_ONLY]], [[ m4_ifdef([[M4_MODE_CXX_ONLY]], [[ b->yy_input_file = file.rdbuf(); ]]) - b->yy_fill_buffer = 1; + + /* b->yy_input_file should never by NULL but we'll handle it cleanly + * on the off chance. + */ + if (b->yy_input_file == NULL){ + b->yy_fill_buffer = 0; + } else { + b->yy_fill_buffer = 1; + } + + /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. diff --git a/src/go-flex.skl b/src/go-flex.skl index 9597a91..e231942 100644 --- a/src/go-flex.skl +++ b/src/go-flex.skl @@ -621,7 +621,11 @@ static void yy_init_buffer(yybuffer b, FILE * file, FlexLexer *yyscanner) yy_flush_buffer(b, yyscanner); b->yyInputFile = file; - b->yyFillBuffer = true; + if (b->yyInputFile == NULL) { + b->yyFillBuffer = false; + } else { + b->yyFillBuffer = true; + } /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. diff --git a/tests/Makefile.am b/tests/Makefile.am index 433fc61..433fc61 100755..100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am diff --git a/tests/yywrap_r.i3.l b/tests/yywrap_r.i3.l index 9e8f162..9e8f162 100755..100644 --- a/tests/yywrap_r.i3.l +++ b/tests/yywrap_r.i3.l |