diff options
| author | Mikkel Stårvik <mikkel.starvik@gmail.com> | 2025-01-28 09:34:04 +0100 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2025-01-29 11:04:00 +0100 |
| commit | a439abb8c991de1c5bbc8d5c105b56599abb9e06 (patch) | |
| tree | b0f1d77048eacd7184187cccdecea0bde5d3d9d9 | |
| parent | fbc5a8136187491e5ee3071e8a60e6593ca9b90b (diff) | |
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
| -rw-r--r-- | render.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -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); } } } |
