scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs | README

commit 6f1e4abb64c2d4204c722d5357da004062f90b92
parent 177976ae00fc60658c6f21739a3fd2462a02917f
Author: Jochen Sprickerhof <git@jochen.sprickerhof.de>
Date:   Wed, 15 Apr 2020 23:08:35 +0200

Error handling for getcursorposition

Diffstat:
Mscroll.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -254,10 +254,17 @@ void getcursorposition(int *x, int *y) { char input[BUFSIZ]; - write(STDOUT_FILENO, "\033[6n", 4); - ssize_t n = read(STDIN_FILENO, input, sizeof(input)-1); + ssize_t n; + + if (write(STDOUT_FILENO, "\033[6n", 4) < 0) + die("requesting cursor position"); + + if ((n = read(STDIN_FILENO, input, sizeof(input)-1)) < 0) + die("reading cursor position"); input[n] = '\0'; - sscanf(input, "\033[%d;%dR", x, y); + + if (sscanf(input, "\033[%d;%dR", x, y) != 2) + die("parsing cursor position"); } void