9
0
Fork 0

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 ada160a34a
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>
This commit is contained in:
Sascha Hauer 2014-09-01 10:21:44 +02:00
parent 45615e3ec1
commit d3f4aa52ca
1 changed files with 5 additions and 1 deletions

View File

@ -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;
}