summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-09-21 19:31:15 +0200
committerwm4 <wm4@nowhere>2020-09-21 19:31:15 +0200
commit95e3a6e67e093741dc6cef37dad3618b5924fa45 (patch)
tree0a18f79ccd2c791f79c4cc230336c53a8f22403d
parent1f21be343a014155b292824d5df862275f85531c (diff)
downloadmpv-95e3a6e67e093741dc6cef37dad3618b5924fa45.tar.bz2
mpv-95e3a6e67e093741dc6cef37dad3618b5924fa45.tar.xz
terminal: fix segfault when backgrounding
In the recent terminal commit, I "compressed" the read() error handling, and messed it up. The return value could be -1 for other non-fatal errors (such as EIO when trying to read while backgrounded), which resulted in buf.len getting messed up. Fixes: 602384348e718c77
-rw-r--r--osdep/terminal-unix.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 80f7b20ddf..8e4d75f78b 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -404,8 +404,10 @@ static void *terminal_thread(void *ptr)
int retval = read(tty_in, &buf.b[buf.len], BUF_LEN - buf.len);
if (!retval || (retval == -1 && (errno == EBADF || errno == EINVAL)))
break; // EOF/closed
- buf.len += retval;
- process_input(input_ctx, false);
+ if (retval > 0) {
+ buf.len += retval;
+ process_input(input_ctx, false);
+ }
}
if (r == 0)
process_input(input_ctx, true);