sway/input/cursor.c: fix undefined behaviour when event is NULL

master
Jason Nader 5 years ago committed by Drew DeVault
parent 6498542b24
commit fcd524bb0d

@ -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); const char *event = libevdev_event_code_get_name(EV_KEY, code);
if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) { if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) {
size_t len = snprintf(NULL, 0, "Event code %d (%s) is not a button", 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); *error = malloc(len);
if (*error) { if (*error) {
snprintf(*error, len, "Event code %d (%s) is not a button", snprintf(*error, len, "Event code %d (%s) is not a button",
code, event); code, event ? event : "(null)");
} }
return 0; return 0;
} }

Loading…
Cancel
Save