From afe2c2df3e289deac770cea2b2bf370e28e26203 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 15 Apr 2025 15:44:42 +0200 Subject: [PATCH] keyboard_control GETCH better err handling GETCH - return always -1 on error, not -1 when read returned 0 and -2 if -1 - the actual value doesn't seem to be checked by any of caller. CID 472180 should be perhaps fixed --- src/keyboard_control.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/keyboard_control.cpp b/src/keyboard_control.cpp index 7593a89d8..6f7004487 100644 --- a/src/keyboard_control.cpp +++ b/src/keyboard_control.cpp @@ -87,6 +87,7 @@ #include "module.h" #include "types.h" // for video_desc #include "utils/color_out.h" +#include "utils/misc.h" // for ug_strerror #include "utils/thread.h" #include "video.h" @@ -310,7 +311,15 @@ GETCH() { unsigned char ch = 0; const ssize_t ret = read(0, &ch, sizeof ch); - return ret <= 0 ? (int) ret - 1 : ch; + if (ret > 0) { + return ch; + } + if (ret == 0) { + MSG(WARNING, "read returned 0!\n"); + } else { + MSG(WARNING, "read error: %s\n", ug_strerror(errno)); + } + return -1; } #else #define GETCH getch