internal/gamepad: fix uint16 underflow handling in gamepads. (#2030)

Fixes crash where Ebiten considers a keyboard a gamepad with way too many buttons.

Updates #2027
This commit is contained in:
divVerent 2022-03-26 02:41:59 -04:00 committed by GitHub
parent dcccd27629
commit 1de1bfef55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -328,7 +328,7 @@ func (g *nativeGamepad) update(gamepad *gamepads) error {
switch e.typ {
case unix.EV_KEY:
if int(e.code)-_BTN_MISC < len(g.keyMap) {
if int(e.code-_BTN_MISC) < len(g.keyMap) {
idx := g.keyMap[e.code-_BTN_MISC]
g.buttons[idx] = e.value != 0
}