[2527] 2009-08-24 Vladimir Serbinenko <[email protected]>

Vladimir Serbinenko <[email protected]> Mon, 24 Aug 2009 19:08:11 +0000
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 2527
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2527
Author:   phcoder
Date:     2009-08-24 19:08:11 +0000 (Mon, 24 Aug 2009)
Log Message:
-----------
2009-08-24  Vladimir Serbinenko  <[email protected]>

	* script/sh/function.c (grub_script_function_find): Cut error message
	not to flood terminal.
	* script/sh/lexer.c (grub_script_yylex): Remove command line length
	limit.
	* script/sh/script.c (grub_script_arg_add): Duplicate string.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/script/sh/function.c
    trunk/grub2/script/sh/lexer.c
    trunk/grub2/script/sh/script.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2009-08-24 17:03:24 UTC (rev 2526)
+++ trunk/grub2/ChangeLog	2009-08-24 19:08:11 UTC (rev 2527)
@@ -1,3 +1,11 @@
+2009-08-24  Vladimir Serbinenko  <[email protected]>
+
+	* script/sh/function.c (grub_script_function_find): Cut error message
+	not to flood terminal.
+	* script/sh/lexer.c (grub_script_yylex): Remove command line length
+	limit.
+	* script/sh/script.c (grub_script_arg_add): Duplicate string.
+
 2009-08-24  Colin Watson  <[email protected]>
 
 	* term/usb_keyboard.c (grub_usb_keyboard_getreport): Make

Modified: trunk/grub2/script/sh/function.c
===================================================================
--- trunk/grub2/script/sh/function.c	2009-08-24 17:03:24 UTC (rev 2526)
+++ trunk/grub2/script/sh/function.c	2009-08-24 19:08:11 UTC (rev 2527)
@@ -99,7 +99,7 @@
       break;
 
   if (! func)
-    grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", functionname);
+    grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%.20s'", functionname);
 
   return func;
 }

Modified: trunk/grub2/script/sh/lexer.c
===================================================================
--- trunk/grub2/script/sh/lexer.c	2009-08-24 17:03:24 UTC (rev 2526)
+++ trunk/grub2/script/sh/lexer.c	2009-08-24 19:08:11 UTC (rev 2527)
@@ -134,8 +134,6 @@
 {
   grub_parser_state_t newstate;
   char use;
-  char *buffer;
-  char *bp;
   struct grub_lexer_param *state = parsestate->lexerstate;
   int firstrun = 1;
 
@@ -212,6 +210,14 @@
       /* Check if it is a text.  */
       if (check_textstate (newstate))
 	{
+	  char *buffer = NULL;
+	  int bufpos = 0;
+	  /* Buffer is initially large enough to hold most commands
+	     but extends automatically when needed.  */
+	  int bufsize = 128;
+
+	  buffer = grub_malloc (bufsize);
+
 	  /* In case the string is not quoted, this can be a one char
 	     length symbol.  */
 	  if (newstate == GRUB_PARSER_STATE_TEXT)
@@ -254,16 +260,12 @@
 		  }
 		}
 	      if (doexit)
-		break;
+		{
+		  grub_free (buffer);
+		  break;
+		}
 	    }
 
-	  /* XXX: Use a better size.  */
-	  buffer = grub_script_malloc (parsestate, 2048);
-	  if (! buffer)
-	    return 0;
-
-	  bp = buffer;
-
 	  /* Read one token, possible quoted.  */
 	  while (*state->script)
 	    {
@@ -295,32 +297,47 @@
 		    }
 		  if (breakout)
 		    break;
-		  if (use)
-		    *(bp++) = use;
 		}
-	      else if (use)
-		*(bp++) = use;
 
+	      if (use)
+		{
+		  if (bufsize <= bufpos + 1)
+		    {
+		      bufsize <<= 1;
+		      buffer = grub_realloc (buffer, bufsize);
+		    }
+		  buffer[bufpos++] = use;
+		}
+
 	      state->state = newstate;
 	      nextchar (state);
 	    }
 
 	  /* A string of text was read in.  */
-	  *bp = '\0';
+	  if (bufsize <= bufpos + 1)
+	    {
+	      bufsize <<= 1;
+	      buffer = grub_realloc (buffer, bufsize);
+	    }
+
+	  buffer[bufpos++] = 0;
+
 	  grub_dprintf ("scripting", "token=`%s'\n", buffer);
 	  yylval->arg = grub_script_arg_add (parsestate, yylval->arg,
 					     GRUB_SCRIPT_ARG_TYPE_STR, buffer);
 
+	  grub_free (buffer);
 	}
       else if (newstate == GRUB_PARSER_STATE_VAR
 	       || newstate == GRUB_PARSER_STATE_QVAR)
 	{
-	  /* XXX: Use a better size.  */
-	  buffer = grub_script_malloc (parsestate, 2096);
-	  if (! buffer)
-	    return 0;
+	  char *buffer = NULL;
+	  int bufpos = 0;
+	  /* Buffer is initially large enough to hold most commands
+	     but extends automatically when needed.  */
+	  int bufsize = 128;
 
-	  bp = buffer;
+	  buffer = grub_malloc (bufsize);
 
 	  /* This is a variable, read the variable name.  */
 	  while (*state->script)
@@ -340,16 +357,33 @@
 		}
 
 	      if (use)
-		*(bp++) = use;
+		{
+		  if (bufsize <= bufpos + 1)
+		    {
+		      bufsize <<= 1;
+		      buffer = grub_realloc (buffer, bufsize);
+		    }
+		  buffer[bufpos++] = use;
+		}
+
 	      nextchar (state);
 	      state->state = newstate;
 	    }
 
-	  *bp = '\0';
+	  if (bufsize <= bufpos + 1)
+	    {
+	      bufsize <<= 1;
+	      buffer = grub_realloc (buffer, bufsize);
+	    }
+
+	  buffer[bufpos++] = 0;
+
 	  state->state = newstate;
 	  yylval->arg = grub_script_arg_add (parsestate, yylval->arg,
 					     GRUB_SCRIPT_ARG_TYPE_VAR, buffer);
 	  grub_dprintf ("scripting", "vartoken=`%s'\n", buffer);
+
+	  grub_free (buffer);
 	}
       else
 	{

Modified: trunk/grub2/script/sh/script.c
===================================================================
--- trunk/grub2/script/sh/script.c	2009-08-24 17:03:24 UTC (rev 2526)
+++ trunk/grub2/script/sh/script.c	2009-08-24 19:08:11 UTC (rev 2527)
@@ -110,10 +110,13 @@
 {
   struct grub_script_arg *argpart;
   struct grub_script_arg *ll;
+  int len;
 
   argpart = (struct grub_script_arg *) grub_script_malloc (state, sizeof (*arg));
   argpart->type = type;
-  argpart->str = str;
+  len = grub_strlen (str) + 1;
+  argpart->str = grub_script_malloc (state, len);
+  grub_memcpy (argpart->str, str, len);
   argpart->next = 0;
 
   if (! arg)