From a439abb8c991de1c5bbc8d5c105b56599abb9e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20St=C3=A5rvik?= Date: Tue, 28 Jan 2025 09:34:04 +0100 Subject: Check if keymap is NULL before dereferencing This avoids segfaulting when a frame is rendered before a keymap has been received, which happens consistently on some systems when swaylock is started after starting the suspend process --- render.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 1aa8ae5..a5e978f 100644 --- a/render.c +++ b/render.c @@ -166,19 +166,21 @@ static bool render_frame(struct swaylock_surface *surface) { } } - xkb_layout_index_t num_layout = xkb_keymap_num_layouts(state->xkb.keymap); - if (!state->args.hide_keyboard_layout && - (state->args.show_keyboard_layout || num_layout > 1)) { - xkb_layout_index_t curr_layout = 0; - - // advance to the first active layout (if any) - while (curr_layout < num_layout && - xkb_state_layout_index_is_active(state->xkb.state, - curr_layout, XKB_STATE_LAYOUT_EFFECTIVE) != 1) { - ++curr_layout; + if (state->xkb.keymap) { + xkb_layout_index_t num_layout = xkb_keymap_num_layouts(state->xkb.keymap); + if (!state->args.hide_keyboard_layout && + (state->args.show_keyboard_layout || num_layout > 1)) { + xkb_layout_index_t curr_layout = 0; + + // advance to the first active layout (if any) + while (curr_layout < num_layout && + xkb_state_layout_index_is_active(state->xkb.state, + curr_layout, XKB_STATE_LAYOUT_EFFECTIVE) != 1) { + ++curr_layout; + } + // will handle invalid index if none are active + layout_text = xkb_keymap_layout_get_name(state->xkb.keymap, curr_layout); } - // will handle invalid index if none are active - layout_text = xkb_keymap_layout_get_name(state->xkb.keymap, curr_layout); } } } -- cgit v1.2.3