[syslinux:firmware] com32: Fix a bug on history of commands.

syslinux-bot for Raphael S.Carvalho raphael.scarv at gmail.com
Mon Sep 30 07:54:05 PDT 2013


Commit-ID:  4ebdc72e001a4bd9f7280e0599e78be116740382
Gitweb:     http://www.syslinux.org/commit/4ebdc72e001a4bd9f7280e0599e78be116740382
Author:     Raphael S.Carvalho <raphael.scarv at gmail.com>
AuthorDate: Tue, 17 Sep 2013 16:52:10 -0300
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Mon, 30 Sep 2013 15:18:31 +0100

com32: Fix a bug on history of commands.

Previously, even zero-length commands would be added to the history when
they shoudn't, e.g: just typing enter.

For example, if you type: FOO -> (ENTER) -> (ENTER),
then to get FOO from the history you would have to press the UP key
twice. It also saves a bit of memory.

Signed-off-by: Raphael S.Carvalho <raphael.scarv at gmail.com>
Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/cli.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index a50124c..6ff30c6 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -461,11 +461,14 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 
     printf("\033[?7h");
 
-    /* Add the command to the history */
-    comm_counter = malloc(sizeof(struct cli_command));
-    comm_counter->command = malloc(sizeof(char) * (strlen(ret) + 1));
-    strcpy(comm_counter->command, ret);
-    list_add(&(comm_counter->list), &cli_history_head);
+    /* Add the command to the history if its length is larger than 0 */
+    len = strlen(ret);
+    if (len > 0) {
+	comm_counter = malloc(sizeof(struct cli_command));
+	comm_counter->command = malloc(sizeof(char) * (len + 1));
+	strcpy(comm_counter->command, ret);
+	list_add(&(comm_counter->list), &cli_history_head);
+    }
 
     return len ? ret : NULL;
 }


More information about the Syslinux-commits mailing list