X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=readline.c;h=92f9cd1569a657a10f0a9c1e2177ca522d5c6a3c;hb=76e4e1d23711750f777333654f13cf6baf8d01f1;hp=9c4b68b53dcd5b09020851af0d55ca9e3621e2e8;hpb=2724b1806a63d66148cea62e1fe1cae3b417bc7e;p=qemu.git diff --git a/readline.c b/readline.c index 9c4b68b53..92f9cd156 100644 --- a/readline.c +++ b/readline.c @@ -28,6 +28,7 @@ #define IS_ESC 1 #define IS_CSI 2 +#undef printf #define printf do_not_use_printf void readline_show_prompt(ReadLineState *rs) @@ -196,12 +197,14 @@ static void readline_up_char(ReadLineState *rs) static void readline_down_char(ReadLineState *rs) { - if (rs->hist_entry == READLINE_MAX_CMDS - 1 || rs->hist_entry == -1) - return; - if (rs->history[++rs->hist_entry] != NULL) { + if (rs->hist_entry == -1) + return; + if (rs->hist_entry < READLINE_MAX_CMDS - 1 && + rs->history[++rs->hist_entry] != NULL) { pstrcpy(rs->cmd_buf, sizeof(rs->cmd_buf), rs->history[rs->hist_entry]); } else { + rs->cmd_buf[0] = 0; rs->hist_entry = -1; } rs->cmd_buf_index = rs->cmd_buf_size = strlen(rs->cmd_buf); @@ -465,9 +468,6 @@ ReadLineState *readline_init(Monitor *mon, { ReadLineState *rs = qemu_mallocz(sizeof(*rs)); - if (!rs) - return NULL; - rs->hist_entry = -1; rs->mon = mon; rs->completion_finder = completion_finder;