Skip to content

Commit afe2c2d

Browse files
committed
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
1 parent 2e555c7 commit afe2c2d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/keyboard_control.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "module.h"
8888
#include "types.h" // for video_desc
8989
#include "utils/color_out.h"
90+
#include "utils/misc.h" // for ug_strerror
9091
#include "utils/thread.h"
9192
#include "video.h"
9293

@@ -310,7 +311,15 @@ GETCH()
310311
{
311312
unsigned char ch = 0;
312313
const ssize_t ret = read(0, &ch, sizeof ch);
313-
return ret <= 0 ? (int) ret - 1 : ch;
314+
if (ret > 0) {
315+
return ch;
316+
}
317+
if (ret == 0) {
318+
MSG(WARNING, "read returned 0!\n");
319+
} else {
320+
MSG(WARNING, "read error: %s\n", ug_strerror(errno));
321+
}
322+
return -1;
314323
}
315324
#else
316325
#define GETCH getch

0 commit comments

Comments
 (0)