Use xkb_keymap_new_from_buffer instead of xkb_keymap_new_from_string

xkb_keymap_new_from_string just calls xkb_keymap_new_from_buffer with size as `strlen(string)`.

0f1cae0cc4/src/keymap.c (L164)

According to the [spec](https://gitlab.freedesktop.org/wayland/wayland/-/blob/master/protocol/wayland.xml#L2182), MAP_PRIVATE should be used.
This commit is contained in:
Nils 2020-03-25 16:41:11 +00:00 committed by Drew DeVault
parent 73754703c5
commit a6b3a0956b

8
seat.c
View File

@ -15,16 +15,16 @@ static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
swaylock_log(LOG_ERROR, "Unknown keymap format %d, aborting", format);
exit(1);
}
char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
char *map_shm = mmap(NULL, size - 1, PROT_READ, MAP_PRIVATE, fd, 0);
if (map_shm == MAP_FAILED) {
close(fd);
swaylock_log(LOG_ERROR, "Unable to initialize keymap shm, aborting");
exit(1);
}
struct xkb_keymap *keymap = xkb_keymap_new_from_string(
state->xkb.context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1,
struct xkb_keymap *keymap = xkb_keymap_new_from_buffer(
state->xkb.context, map_shm, size - 1, XKB_KEYMAP_FORMAT_TEXT_V1,
XKB_KEYMAP_COMPILE_NO_FLAGS);
munmap(map_shm, size);
munmap(map_shm, size - 1);
close(fd);
assert(keymap);
struct xkb_state *xkb_state = xkb_state_new(keymap);