summaryrefslogtreecommitdiffstats
path: root/lib/readline.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-09-01 10:21:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-09-01 14:24:50 +0200
commitd3f4aa52caf716658ebbf62f107f27ad0c78ffe3 (patch)
tree5afb124ef0cba5221e7ea6be4076da5a6f31a4dd /lib/readline.c
parent45615e3ec10c38298c1b9780e13a884aff49bae1 (diff)
downloadbarebox-d3f4aa52caf716658ebbf62f107f27ad0c78ffe3.tar.gz
barebox-d3f4aa52caf716658ebbf62f107f27ad0c78ffe3.tar.xz
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 <s.hauer@pengutronix.de> Date: Tue Jul 29 11:54:26 2014 +0200 readline: reimplement history functions Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Teresa Gamez <t.gamez@phytec.de>
Diffstat (limited to 'lib/readline.c')
-rw-r--r--lib/readline.c6
1 files changed, 5 insertions, 1 deletions
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;
}