changeset 20219:f185653b2f5e stable

don't crash if structure field is keyword (bug #45092) * lex.ll (handle_identiier): Emit specific error if structure field is a keyword. Error instead of aborting if at_beginning_of_statement is true when parsting a structure field.
author John W. Eaton <jwe@octave.org>
date Wed, 13 May 2015 14:17:08 -0400
parents 4e7f12a763cd
children 7e01182ee36c
files libinterp/parse-tree/lex.ll
diffstat 1 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Tue May 12 10:05:02 2015 -0700
+++ b/libinterp/parse-tree/lex.ll	Wed May 13 14:17:08 2015 -0400
@@ -2893,6 +2893,12 @@
 
   std::string tok = yytxt;
 
+  // If tok is a keyword token, then is_keyword_token will set
+  // at_beginning_of_statement.  For example, if tok is an IF
+  // token, then at_beginning_of_statement will be false.
+
+  int kw_token = is_keyword_token (tok);
+
   // If we are expecting a structure element, avoid recognizing
   // keywords and other special names and return STRUCT_ELT, which is
   // a string that is also a valid identifier.  But first, we have to
@@ -2907,17 +2913,22 @@
 
       current_input_column += flex_yyleng ();
 
-      assert (! at_beginning_of_statement);
+      if (kw_token)
+        {
+          error ("structure fields may not be keywords");
+          return LEXICAL_ERROR;
+        }
+
+      if (at_beginning_of_statement)
+        {
+          error ("invalid syntax for structure reference");
+
+          return LEXICAL_ERROR;
+        }
 
       return STRUCT_ELT;
     }
 
-  // If tok is a keyword token, then is_keyword_token will set
-  // at_beginning_of_statement.  For example, if tok is and IF
-  // token, then at_beginning_of_statement will be false.
-
-  int kw_token = is_keyword_token (tok);
-
   if (looking_at_function_handle)
     {
       if (kw_token)