grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: normal/cmdline bug & patch


From: Tomas Ebenlendr
Subject: Re: normal/cmdline bug & patch
Date: Fri, 18 Jun 2004 23:27:51 +0200
User-agent: Mutt/1.5.6i

> 
> Can you send the patch in an attachment?  (and preferable -up diffed)
> 
I did diff once more and compared the two diffs. They differed in some
whitespaces. I probably deleted them when viewing the patch with vim.
(I store my grub2 patches, because I want to be able reconstruct sources
when I mess them up by my debuging prints.)

Here is the correct patch:

Changelog (probably too much detail):
        Bugfix of grub_set_history.
        * normal/cmdline.c(grub_set_history):
            fix1(55): hist_end points to first _empty_ entry
            fix2(58,2): pos cannot overflow, but can underflow
            fix3(65): correction must act as modulo
            fix4(71)[hist_pos==hist_end]: copy nothing if hist_used == 0
            fix5(73,9): buffer was copied wrong way

--- grub2_nonpatched/normal/cmdline.c   2004-06-18 23:05:53.000000000 +0200
+++ grub2_patched/normal/cmdline.c      2004-06-15 19:55:45.000000000 +0200
@@ -52,33 +52,35 @@ grub_set_history (int newsize)
          int delsize = hist_used - newsize;
          hist_used = newsize;
 
-         for (i = 0; i < delsize; i++)
+         for (i = 1; i <= delsize; i++)
            {
              int pos = hist_end - i;
-             if (pos > hist_size)
-               pos -= hist_size;
+             if (pos < 0)
+               pos += hist_size;
              grub_free (old_hist_lines[pos]);
            }
 
          hist_end -= delsize;
          if (hist_end < 0)
-           hist_end = hist_size - hist_end;
+           hist_end += hist_size;
        }
 
       if (hist_pos < hist_end)
        grub_memmove (hist_lines, old_hist_lines + hist_pos,
                      (hist_end - hist_pos) * sizeof (char *));
-      else
+      else if (hist_used)
        {
-         /* Copy the first part.  */
-         grub_memmove (hist_lines, old_hist_lines,
-                       hist_pos * sizeof (char *));
-
+         /* old_hist_lines: 0 <older part> hist_end <empty> hist_pos <newer 
part> */
+         /* entry at hist_end is empty, at hist_pos contains first entry */
 
-         /* Copy the last part.  */
-         grub_memmove (hist_lines + hist_pos, old_hist_lines + hist_pos,
+         /* Copy the older part.  */
+         grub_memmove (hist_lines, old_hist_lines + hist_pos,
                        (hist_size - hist_pos) * sizeof (char *));
 
+         /* Copy the newer part. */
+         grub_memmove (hist_lines + hist_size - hist_pos, old_hist_lines,
+                       hist_end * sizeof (char *));
+
        }
     }
 
-- 
                                 Tomas 'ebi' Ebenlendr
                                 http://get.to/ebik
                                 PF 2004.46438850309





reply via email to

[Prev in Thread] Current Thread [Next in Thread]