From b06aedb8badc0ed99bad01f11015dd3ac85e50bb Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 2 May 2023 14:15:55 +1000 Subject: scanner: allow for a zero terminated string as keymap As the documentation for xkb_keymap_new_from_buffer() states, the "input string does not have to be zero-terminated". The actual implementation however failed with "unrecognized token/syntax error" when it encountered a null byte. Fix this by allowing a null byte at the last position of the buffer. Anything else is likely a client error anyway. Fixes #307 --- src/keymap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/keymap.c b/src/keymap.c index d2baf94..0291aed 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -194,6 +194,10 @@ xkb_keymap_new_from_buffer(struct xkb_context *ctx, if (!keymap) return NULL; + /* Allow a zero-terminated string as a buffer */ + if (length > 0 && buffer[length - 1] == '\0') + length--; + if (!ops->keymap_new_from_string(keymap, buffer, length)) { xkb_keymap_unref(keymap); return NULL; -- cgit v1.2.1