apprt/embedded: initialize unmodified keystate prior to use

Fixes #521

We were not initializing the dead key state. The dead key state is read
on all translation calls so it must be initialized to 0. This was
working before because coincidentally whatever the memory was always
worked (it probably didn't, but it never didn't work for someone to
notice).

In debug modes, Zig sets uninitialized memory to 0xAAAAAAAA. Amusingly,
this is a valid dead key state value that UCKeyTranslate ignores and
thus produces the correct value. Therefore, we were only seeing bugs in
release modes where the uninitialized memory was a bad value
(consistently 0x1 on my machine) causing the wrong key to come out.

We were getting lucky before, this has always been a bug.
This commit is contained in:
Mitchell Hashimoto
2023-09-22 09:18:52 -07:00
parent 4a774b088b
commit d287e741b1

View File

@ -557,7 +557,7 @@ pub const Surface = struct {
// order to get the "unshifted_codepoint" for the key event.
const unshifted_codepoint: u21 = unshifted: {
var nomod_buf: [128]u8 = undefined;
var nomod_state: input.Keymap.State = undefined;
var nomod_state: input.Keymap.State = .{};
const nomod = try self.app.keymap.translate(
&nomod_buf,
&nomod_state,