On Sat, Aug 01, 2009 at 05:13:27PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> >> > There's a much simpler way to address this. Just add something like:
> >> >
> >> > cmdline_argv = argv + 1;
> >> > cmdline_argc = argc - 1;
> >> >
> >> > at the beginning, and then use cmdline_argv and cmdline_argc instead of
> >> > correcting the off-by-one every time.
> >> Correcting the numbers is actually smaller part of the patch. The most
> >> of it is to make empty commandlines to be handled correctly (this
> >> couldn't happen previously)
> >
> > Either there's an extra argv member that is always present and we want
> > to remove, or there's the possibility that the command-line is empty.
> > AFAICS we can't have both problems.
> >
> No. Now we have an extra element that is always present and we want to
> remove but when we remove command line can be empty and code must
> handle it correctly.
Please try this patch.
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
Index: loader/i386/multiboot.c
===================================================================
--- loader/i386/multiboot.c (revision 2465)
+++ loader/i386/multiboot.c (working copy)
@@ -201,6 +201,8 @@
grub_ssize_t len, cmdline_length, boot_loader_name_length;
grub_uint32_t mmap_length;
int i;
+ int cmdline_argc;
+ char **cmdline_argv;
grub_loader_unset ();
@@ -256,9 +258,12 @@
mmap_length = grub_get_multiboot_mmap_len ();
+ cmdline_argv = argv + 1;
+ cmdline_argc = argc - 1;
+
/* Figure out cmdline length. */
- for (i = 0, cmdline_length = 0; i < argc; i++)
- cmdline_length += grub_strlen (argv[i]) + 1;
+ for (i = 0, cmdline_length = 0; i < cmdline_argc; i++)
+ cmdline_length += grub_strlen (cmdline_argv[i]) + 1;
boot_loader_name_length = sizeof(PACKAGE_STRING);
@@ -351,9 +356,9 @@
if (! cmdline)
goto fail;
- for (i = 0; i < argc; i++)
+ for (i = 0; i < cmdline_argc; i++)
{
- p = grub_stpcpy (p, argv[i]);
+ p = grub_stpcpy (p, cmdline_argv[i]);
*(p++) = ' ';
}
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel