[hackers] [scroll] Error handling for getcursorposition || Jochen Sprickerhof

From: <git_AT_suckless.org>
Date: Thu, 16 Apr 2020 01:50:22 +0200 (CEST)

commit 6f1e4abb64c2d4204c722d5357da004062f90b92
Author: Jochen Sprickerhof <git_AT_jochen.sprickerhof.de>
AuthorDate: Wed Apr 15 23:08:35 2020 +0200
Commit: Jochen Sprickerhof <git_AT_jochen.sprickerhof.de>
CommitDate: Wed Apr 15 23:08:35 2020 +0200

    Error handling for getcursorposition

diff --git a/scroll.c b/scroll.c
index dd44d8d..a87ac88 100644
--- a/scroll.c
+++ b/scroll.c
_AT_@ -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
Received on Thu Apr 16 2020 - 01:50:22 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 16 2020 - 02:00:37 CEST