From fcd524bb0d6f3c6cd4f2ddc180520bc56a89aa4a Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Sun, 15 Mar 2020 17:51:10 +0900 Subject: [PATCH] sway/input/cursor.c: fix undefined behaviour when event is NULL --- sway/input/cursor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index e41acd8bd..3a4a69b67 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -1059,11 +1059,11 @@ uint32_t get_mouse_bindcode(const char *name, char **error) { const char *event = libevdev_event_code_get_name(EV_KEY, code); if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) { size_t len = snprintf(NULL, 0, "Event code %d (%s) is not a button", - code, event) + 1; + code, event ? event : "(null)") + 1; *error = malloc(len); if (*error) { snprintf(*error, len, "Event code %d (%s) is not a button", - code, event); + code, event ? event : "(null)"); } return 0; }