From: marco_g Date: Sun, 27 Jun 2004 11:03:24 +0000 (+0000) Subject: 2004-06-27 Tomas Ebenlendr X-Git-Tag: 1.98~2212 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfb12aff2821238e69fb7c7c6104f2730016b173;p=thirdparty%2Fgrub.git 2004-06-27 Tomas Ebenlendr * normal/cmdline.c (grub_set_history): Fix off by one bug. Fixed the history buffer logic. --- diff --git a/ChangeLog b/ChangeLog index 450f70592..05fc4b5a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-06-27 Tomas Ebenlendr + + * normal/cmdline.c (grub_set_history): Fix off by one bug. Fixed + the history buffer logic. + 2004-06-27 Tomas Ebenlendr * fs/ext2.c (FILETYPE_INO_MASK, FILETYPE_INO_DIRECTORY) diff --git a/normal/cmdline.c b/normal/cmdline.c index b4d2a16f3..b53a630f1 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -52,33 +52,31 @@ 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 *)); - - - /* Copy the last part. */ - grub_memmove (hist_lines + hist_pos, old_hist_lines + hist_pos, - (hist_size - hist_pos) * sizeof (char *)); - + /* 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 *)); } }