From d3f4aa52caf716658ebbf62f107f27ad0c78ffe3 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 1 Sep 2014 10:21:44 +0200 Subject: readline: Fix history prev when history is empty We cannot use list_entry() on an empty list. Without history we have to return an empty line. This fixes a crash when the cursor up button is pressed and no command has been entered previously. Broken since: commit ada160a34a1ec8421d5bb7b9dd746294668a5130 Author: Sascha Hauer Date: Tue Jul 29 11:54:26 2014 +0200 readline: reimplement history functions Signed-off-by: Sascha Hauer Reported-by: Teresa Gamez --- lib/readline.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/readline.c b/lib/readline.c index b70bca8554..14dd31171d 100644 --- a/lib/readline.c +++ b/lib/readline.c @@ -68,8 +68,12 @@ static const char *hist_prev(void) struct history *history; if (history_current->prev == &history_list) { - history = list_entry(history_current, struct history, list); getcmd_cbeep(); + + if (list_empty(&history_list)) + return ""; + + history = list_entry(history_current, struct history, list); return history->line; } -- cgit v1.2.3