From 6e6979990d9a87df8283b5aac5d2f688b82501f7 Mon Sep 17 00:00:00 2001 From: jakobrs Date: Tue, 6 Jul 2021 14:27:55 +0200 Subject: [PATCH] Check if keysym_return == NULL before using --- src/library/inputs/xkeyboardlayout.cpp | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/library/inputs/xkeyboardlayout.cpp b/src/library/inputs/xkeyboardlayout.cpp index c52d379c..e73e0f89 100644 --- a/src/library/inputs/xkeyboardlayout.cpp +++ b/src/library/inputs/xkeyboardlayout.cpp @@ -180,7 +180,9 @@ static const char Xlib_default_char[256] = { debuglogstdio(LCF_KEYBOARD, "%s called with keycode %d", __func__, event_struct->keycode); // printBacktrace(); KeyCode keycode = event_struct->keycode; - *keysym_return = Xlib_default_keymap[keycode]; + if (keysym_return) { + *keysym_return = Xlib_default_keymap[keycode]; + } if (buffer_return && (bytes_buffer > 0)) { char c = Xlib_default_char[keycode]; if (c == '\0') { @@ -196,23 +198,26 @@ static const char Xlib_default_char[256] = { { debuglogstdio(LCF_KEYBOARD, "%s called with keycode %d", __func__, event->keycode); KeyCode keycode = event->keycode; - *keysym_return = Xlib_default_keymap[keycode]; + KeySym keysym = Xlib_default_keymap[keycode]; /* Return if no associated keysym */ - if (*keysym_return == NoSymbol) { + if (keysym == NoSymbol) { *status_return = XLookupNone; return 0; } + if (keysym_return) + *keysym_return = keysym; + char c = Xlib_default_char[keycode]; /* Return if no associated string */ if (c == '\0') { - *status_return = XLookupKeySym; + *status_return = keysym_return ? XLookupKeySym : XLookupNone; return 0; } - *status_return = XLookupBoth; + *status_return = keysym_return ? XLookupBoth : XLookupChars; if (buffer_return && (bytes_buffer > 0)) { buffer_return[0] = c; return 1; @@ -224,23 +229,27 @@ static const char Xlib_default_char[256] = { { debuglogstdio(LCF_KEYBOARD, "%s called with keycode %d", __func__, event->keycode); KeyCode keycode = event->keycode; - *keysym_return = Xlib_default_keymap[keycode]; + KeySym keysym = Xlib_default_keymap[keycode]; /* Return if no associated keysym */ - if (*keysym_return == NoSymbol) { + if (keysym == NoSymbol) { *status_return = XLookupNone; return 0; } + if (keysym_return) { + *keysym_return = keysym; + } + char c = Xlib_default_char[keycode]; /* Return if no associated string */ if (c == '\0') { - *status_return = XLookupKeySym; + *status_return = keysym_return ? XLookupKeySym : XLookupNone; return 0; } - *status_return = XLookupBoth; + *status_return = keysym_return ? XLookupBoth : XLookupChars; if (buffer_return && (wchars_buffer > 0)) { buffer_return[0] = c; return 1;