[syslinux:elflink] CLI: Fix command history traversal

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon Nov 5 08:03:08 PST 2012


Commit-ID:  c7381a5cef7f38e0176b8bc90e7ca54c4d0711d2
Gitweb:     http://www.syslinux.org/commit/c7381a5cef7f38e0176b8bc90e7ca54c4d0711d2
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 1 Nov 2012 10:56:06 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 2 Nov 2012 14:06:20 +0000

CLI: Fix command history traversal

The up/down keys were broken with respect to traversing through the
command history because it was dereferencing a NULL pointer on the
first iteration.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/cli.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index a1cf50c..65a5057 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -340,9 +340,16 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	case KEY_UP:
 	    {
 		if (!list_empty(&cli_history_head)) {
+		    struct list_head *next;
+
+		    if (!comm_counter)
+			next = cli_history_head.next;
+		    else
+			next = comm_counter->list.next;
+
 		    comm_counter =
-			list_entry(comm_counter->list.next,
-				   typeof(*comm_counter), list);
+			list_entry(next, typeof(*comm_counter), list);
+
 		    if (&comm_counter->list == &cli_history_head) {
 			strcpy(cmdline, temp_cmdline);
 		    } else {
@@ -357,9 +364,16 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	case KEY_DOWN:
 	    {
 		if (!list_empty(&cli_history_head)) {
+		    struct list_head *prev;
+
+		    if (!comm_counter)
+			prev = cli_history_head.prev;
+		    else
+			prev = comm_counter->list.prev;
+
 		    comm_counter =
-			list_entry(comm_counter->list.prev,
-				   typeof(*comm_counter), list);
+			list_entry(prev, typeof(*comm_counter), list);
+
 		    if (&comm_counter->list == &cli_history_head) {
 			strcpy(cmdline, temp_cmdline);
 		    } else {


More information about the Syslinux-commits mailing list