lexer: Make lex_error_expecting_valist() support a longer list.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 18 Sep 2022 23:42:26 +0000 (16:42 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 18 Sep 2022 23:42:26 +0000 (16:42 -0700)
src/language/lexer/lexer.c

index f9236af19fc394cb55d63f90ded975f2218f10d1..a2a0da9713c8f044398af94c0cb5c94580a095a7 100644 (file)
@@ -519,18 +519,22 @@ void
 void
 lex_error_expecting_valist (struct lexer *lexer, va_list args)
 {
-  enum { MAX_OPTIONS = 9 };
-  const char *options[MAX_OPTIONS];
-  int n = 0;
-  while (n < MAX_OPTIONS)
+  const char **options = NULL;
+  size_t allocated = 0;
+  size_t n = 0;
+
+  for (;;)
     {
       const char *option = va_arg (args, const char *);
       if (!option)
         break;
 
+      if (n >= allocated)
+        options = x2nrealloc (options, &allocated, sizeof *options);
       options[n++] = option;
     }
   lex_error_expecting_array (lexer, options, n);
+  free (options);
 }
 
 void