Received: from eggs.gnu.org ([2001:4830:134:3::10]:41757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXqtW-0001XC-5N for qemu-devel@nongnu.org; Thu, 11 Aug 2016 10:23:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXqtV-0007zi-8S for qemu-devel@nongnu.org; Thu, 11 Aug 2016 10:23:38 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXqtV-0007wH-16 for qemu-devel@nongnu.org; Thu, 11 Aug 2016 10:23:37 -0400 From: Peter Maydell Date: Thu, 11 Aug 2016 15:23:27 +0100 Message-Id: <1470925407-23850-3-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1470925407-23850-1-git-send-email-peter.maydell@linaro.org> References: <1470925407-23850-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH 2/2] ui/curses.c: Clean up nextchr logic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: patches@linaro.org, Gerd Hoffmann Coverity identifies that at the top of the while(1) loop in curses_refresh() the variable nextchr is always ERR, and so the else case of the first if() is dead code. Remove this dead code, and narrow the scope of the nextchr variable to the place where it's used. (This confused logic has been present since the curses code was added to QEMU in 2008.) Signed-off-by: Peter Maydell --- ui/curses.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index f1f886c..d06f724 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -181,7 +181,7 @@ static kbd_layout_t *kbd_layout = NULL; static void curses_refresh(DisplayChangeListener *dcl) { - int chr, nextchr, keysym, keycode, keycode_alt; + int chr, keysym, keycode, keycode_alt; curses_winch_check(); @@ -195,15 +195,9 @@ static void curses_refresh(DisplayChangeListener *dcl) graphic_hw_text_update(NULL, screen); - nextchr = ERR; while (1) { /* while there are any pending key strokes to process */ - if (nextchr == ERR) - chr = getch(); - else { - chr = nextchr; - nextchr = ERR; - } + chr = getch(); if (chr == ERR) break; @@ -224,13 +218,12 @@ static void curses_refresh(DisplayChangeListener *dcl) /* alt key */ if (keycode == 1) { - nextchr = getch(); + int nextchr = getch(); if (nextchr != ERR) { chr = nextchr; keycode_alt = ALT; - keycode = curses2keycode[nextchr]; - nextchr = ERR; + keycode = curses2keycode[chr]; if (keycode != -1) { keycode |= ALT; -- 2.7.4