All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUGFIX] Fix rescue parser
@ 2009-10-15 13:06 Vladimir 'phcoder' Serbinenko
  2009-10-16 18:34 ` Robert Millan
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-10-15 13:06 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 108 bytes --]


-- 
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git 


[-- Attachment #2: parres.diff --]
[-- Type: text/x-patch, Size: 3416 bytes --]

diff --git a/ChangeLog b/ChangeLog
index b0864a9..55bdc92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
 
+	* kern/parser.c (grub_parser_split_cmdline): Fix incorrect counting
+	of arguments. Return number of tokens and not arguments. All users
+	updated.
+
+2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
+
 	* loader/i386/pc/xnu.c (grub_xnu_set_video): Fix loading splash image.
 
 2009-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
diff --git a/kern/parser.c b/kern/parser.c
index db59af0..006d67d 100644
--- a/kern/parser.c
+++ b/kern/parser.c
@@ -142,7 +142,7 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
 	*(bp++) = *val;
     }
 
-  *argc = 1;
+  *argc = 0;
   do
     {
       if (! *rd)
@@ -188,12 +188,16 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
 	  state = newstate;
 	}
     } while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
-  *(bp++) = '\0';
 
   /* A special case for when the last character was part of a
      variable.  */
   add_var (GRUB_PARSER_STATE_TEXT);
 
+  if (bp != buffer && *(bp - 1))
+    {
+      *(bp++) = '\0';
+      (*argc)++;
+    }
 
   /* Reserve memory for the return values.  */
   args = grub_malloc (bp - buffer);
@@ -219,8 +223,6 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
       bp++;
     }
 
-  (*argc)--;
-
   return 0;
 }
 
diff --git a/kern/rescue_parser.c b/kern/rescue_parser.c
index 1e0841e..d3725e7 100644
--- a/kern/rescue_parser.c
+++ b/kern/rescue_parser.c
@@ -35,9 +35,12 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
   if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0)
     return grub_errno;
 
+  if (n == 0)
+    return GRUB_ERR_NONE;
+
   /* In case of an assignment set the environment accordingly
      instead of calling a function.  */
-  if (n == 0 && grub_strchr (line, '='))
+  if (n == 1 && grub_strchr (line, '='))
     {
       char *val = grub_strchr (args[0], '=');
       val[0] = 0;
@@ -56,7 +59,7 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
   cmd = grub_command_find (name);
   if (cmd)
     {
-      (cmd->func) (cmd, n, &args[1]);
+      (cmd->func) (cmd, n - 1, &args[1]);
     }
   else
     {
diff --git a/normal/completion.c b/normal/completion.c
index 4b38e33..d264028 100644
--- a/normal/completion.c
+++ b/normal/completion.c
@@ -409,13 +409,16 @@ grub_normal_do_completion (char *buf, int *restore,
   if (grub_parser_split_cmdline (buf, 0, &argc, &argv))
     return 0;
 
-  current_word = argv[argc];
+  if (argc == 0)
+    current_word = "";
+  else
+    current_word = argv[argc - 1];
 
   /* Determine the state the command line is in, depending on the
      state, it can be determined how to complete.  */
   cmdline_state = get_state (buf);
 
-  if (argc == 0)
+  if (argc == 1 || argc == 0)
     {
       /* Complete a command.  */
       if (grub_command_iterate (iterate_command))
@@ -485,13 +488,15 @@ grub_normal_do_completion (char *buf, int *restore,
           goto fail;
 	}
 
-      grub_free (argv[0]);
+      if (argc != 0)
+	grub_free (argv[0]);
       grub_free (match);
       return ret;
     }
 
  fail:
-  grub_free (argv[0]);
+  if (argc != 0)
+    grub_free (argv[0]);
   grub_free (match);
   grub_errno = GRUB_ERR_NONE;
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-16 18:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-15 13:06 [BUGFIX] Fix rescue parser Vladimir 'phcoder' Serbinenko
2009-10-16 18:34 ` Robert Millan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.