From a2993ea104ca1d9a04fb01b163828b0a08ff95d9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 8 Oct 2019 18:38:05 +1100 Subject: [PATCH] Check that stdin is readable before calling read This should not be necessary, but it works around a bug in WSL. Fixes #3112 --- src/ncurses_ui.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 3e1a4c6b..85785f9a 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -5,6 +5,7 @@ #include "keys.hh" #include "ranges.hh" #include "string_utils.hh" +#include "file.hh" #include @@ -579,7 +580,7 @@ Optional NCursesUI::get_next_key() static auto get_char = []() -> Optional { unsigned char c = 0; - if (read(STDIN_FILENO, &c, 1) == 1) + if (fd_readable(STDIN_FILENO) and read(STDIN_FILENO, &c, 1) == 1) return c; return {}; };