commit cef484cbcf0ba83757f853f235a6cc7497448fa2 Rainer Holzner <rholzner@web.de> 2024-12-20 18:01:52 +0100 Fix infinite loop caused by search prompt This fixes an infinite loop when the user selects item type 7 (IND), enters 1 or more characters and decides to cancel the search prompt by pressing Ctrl+D without deleting the input line. Note that the fixed version requires the user to press Ctrl-D twice in this case.
ui_ti.c | 3 ++- ui_txt.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/ui_ti.c b/ui_ti.c index e256611..c42bbd0 100644 --- a/ui_ti.c +++ b/ui_ti.c @@ -97,7 +97,7 @@ uiprompt(char *fmt, ...) putp(tparm(restore_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0)); fflush(stdout); - if (r == -1) { + if (r == -1 || feof(stdin)) { clearerr(stdin); clear(&input); } else if (input[r - 1] == '\n') { @@ -531,6 +531,7 @@ uiselectitem(Item *entry) case _key_searchprev: searchinline(searchstr, entry, -1); continue; + case EOF: case 0x04: case _key_quit: quit: diff --git a/ui_txt.c b/ui_txt.c index e8f8bbe..02c97be 100644 --- a/ui_txt.c +++ b/ui_txt.c @@ -124,7 +124,7 @@ uiprompt(char *fmt, ...) mbsprint(bufout, columns); fflush(stdout); - if ((r = getline(&input, &n, stdin)) == -1) { + if ((r = getline(&input, &n, stdin)) == -1 || feof(stdin)) { clearerr(stdin); clear(&input); putchar('\n');