changeset 28118:2a186f34eb96 stable

in push lexer, don't insert NL with ASCII 1 marker (bug #57859) * lex.ll (push_lexer::fill_flex_buffer): Avoid inserting newline character in buffer after ASCII 1 marker used to tell lexer to get more input.
author John W. Eaton <jwe@octave.org>
date Wed, 19 Feb 2020 15:21:28 -0500
parents b0f949055097
children 34a3d005e2ad 273db03ab762
files libinterp/parse-tree/lex.ll
diffstat 1 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Mon Feb 17 17:37:20 2020 +0100
+++ b/libinterp/parse-tree/lex.ll	Wed Feb 19 15:21:28 2020 -0500
@@ -3798,19 +3798,30 @@
   {
     int status = 0;
 
-    // If the input buffer is empty or we are at the end of the buffer,
-    // insert ASCII 1 as a marker for subsequent rules.
-
     if (m_input_buf.empty () && ! m_input_buf.at_eof ())
-      m_input_buf.fill (std::string (1, static_cast<char> (1)), false);
-
-    // Note that the copy_chunk function may append a newline character
-    // to the input.
-
-    if (! m_input_buf.empty ())
-      status = m_input_buf.copy_chunk (buf, max_size);
+      {
+        // If the input buffer is empty or we are at the end of the
+        // buffer, insert ASCII 1 as a marker for subsequent rules.
+        // Don't insert a newline character in this case.  Instead of
+        // calling input_buffer::fill followed immediately by
+        // input_buffer::copy_chunk, simply insert the marker directly
+        // in BUF.
+
+        assert (max_size > 0);
+
+        buf[0] = static_cast<char> (1);
+        status = 1;
+      }
     else
-      status = YY_NULL;
+      {
+        // Note that the copy_chunk function may append a newline
+        // character to the input.
+
+        if (! m_input_buf.empty ())
+          status = m_input_buf.copy_chunk (buf, max_size);
+        else
+          status = YY_NULL;
+      }
 
     return status;
   }