keysym: fix underflow in binary searches
authorIsaac Freund <ifreund@ifreund.xyz>
Wed, 21 Apr 2021 22:37:03 +0000 (00:37 +0200)
committerRan Benita <ran@unusedvar.com>
Sun, 25 Apr 2021 09:25:58 +0000 (12:25 +0300)
commit68dddd4132521dc72133a4f0010d0d07ec30a16e
tree3d2d8f6aa75a0f3b903cd0390f56b3c0e858e7a0
parent1557668364496ecd724d8f80f915e0c9d6be803e
keysym: fix underflow in binary searches

This is hit when passing an empty string and XKB_KEYSYM_CASE_INSENSITIVE
to xkb_keysym_from_name currently if `(lo + hi) / 2` is 0 and `cmp < 0`,
causing mid to underflow and the the array access into name_to_keysym on
the next iteration of the loop to be out of bounds .

We *would* use ssize_t here as it is the appropriate type, but windows
unfortunately does not define it.
src/keysym.c
test/keysym.c