From 56092814f3a1338a219dcab275b22463d6f95182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 19 Jul 2021 19:05:32 +0200 Subject: [PATCH] Improve error description for invalid scancodes --- src/cocoa_window.m | 2 +- src/null_window.c | 6 ++++++ src/win32_window.c | 2 +- src/x11_window.c | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 8fe992d5..5b8396b4 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1536,7 +1536,7 @@ const char* _glfwPlatformGetScancodeName(int scancode) if (scancode < 0 || scancode > 0xff || _glfw.ns.keycodes[scancode] == GLFW_KEY_UNKNOWN) { - _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode"); + _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; } diff --git a/src/null_window.c b/src/null_window.c index 3e446641..b81ab601 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -524,6 +524,12 @@ const char* _glfwPlatformGetClipboardString(void) const char* _glfwPlatformGetScancodeName(int scancode) { + if (scancode < GLFW_KEY_SPACE || scancode > GLFW_KEY_LAST) + { + _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); + return NULL; + } + switch (scancode) { case GLFW_KEY_APOSTROPHE: diff --git a/src/win32_window.c b/src/win32_window.c index 52a9c680..13126292 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -2108,7 +2108,7 @@ const char* _glfwPlatformGetScancodeName(int scancode) if (scancode < 0 || scancode > (KF_EXTENDED | 0xff) || _glfw.win32.keycodes[scancode] == GLFW_KEY_UNKNOWN) { - _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode"); + _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; } diff --git a/src/x11_window.c b/src/x11_window.c index 3f2277d6..d7b85994 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2891,7 +2891,7 @@ const char* _glfwPlatformGetScancodeName(int scancode) if (scancode < 0 || scancode > 0xff || _glfw.x11.keycodes[scancode] == GLFW_KEY_UNKNOWN) { - _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode"); + _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; }