From d91d30cfaf5198d512ba3864f4c9cc17cc0504ef Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Fri, 23 Aug 2024 22:27:03 +0200 Subject: Check return value of glfwGetKeyName --- xnote.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xnote.c b/xnote.c index c35193c..0541374 100644 --- a/xnote.c +++ b/xnote.c @@ -155,12 +155,12 @@ undo(void) case EVENT_START_LINE: case EVENT_START_NOTE: case EVENT_START: - goto exit; + break; default: continue; } + break; } -exit: shrink(&events, event_count, &event_cap, sizeof(enum event)); } @@ -244,9 +244,10 @@ static void key_press_cb(GLFWwindow *window, int key, int scancode, int action, int mods) { if (action == GLFW_PRESS || action == GLFW_REPEAT) { - if ((mods & GLFW_MOD_CONTROL) && !strcmp(glfwGetKeyName(key, scancode), "z")) { + const char *keysym = glfwGetKeyName(key, scancode); + if ((mods & GLFW_MOD_CONTROL) && keysym && !strcmp(keysym, "z")) { if (event_count) undo(); - } else if ((mods & GLFW_MOD_CONTROL) && !strcmp(glfwGetKeyName(key, scancode), "c")) { + } else if ((mods & GLFW_MOD_CONTROL) && keysym && !strcmp(keysym, "c")) { for (size_t i = 0; i < line_count; i++) free(lines[i].points); line_count = 0; -- cgit v1.2.3-71-gd317