aboutsummaryrefslogtreecommitdiffstats
path: root/com32/elflink/ldlinux
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-11-01 10:56:06 +0000
committerMatt Fleming <matt.fleming@intel.com>2012-11-02 14:06:20 +0000
commitc7381a5cef7f38e0176b8bc90e7ca54c4d0711d2 (patch)
treeff8c9917a7860c4a4f9816b35b3d4baf07d7cf31 /com32/elflink/ldlinux
parente55d4988880a538fa81fe6bb2bf4fd5604174f06 (diff)
downloadsyslinux-c7381a5cef7f38e0176b8bc90e7ca54c4d0711d2.tar.gz
syslinux-c7381a5cef7f38e0176b8bc90e7ca54c4d0711d2.tar.xz
syslinux-c7381a5cef7f38e0176b8bc90e7ca54c4d0711d2.zip
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@intel.com>
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r--com32/elflink/ldlinux/cli.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index a1cf50cc..65a50577 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 {