Skip to contentSkip to conversation

input-linux: fix Coverity warning

PATCH In review Gerd Hoffmann 2 participants 3 messages Mar 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input-linux: fix Coverity warning

---
 ui/input-linux.c | 7 +++++++
 1 file changed, 7 insertions(+)
ui/input-linux.c +7 -0
index 76a2abb..f884c00 100644
@@ -257,6 +257,13 @@ static void input_linux_event_keyboard(void *opaque)
                  */
                 continue;
             }
+            if (event.code >= KEY_CNT) {
+                /*
+                 * Should not happen.  But better safe than sorry,
+                 * and we make Coverity happy too.
+                 */
+                continue;
+            }
             /* keep track of key state */
             if (!il->keydown[event.code] && event.value) {
                 il->keydown[event.code] = true;
Signature · 1 line
1.8.3.1
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Am 16.03.2016 um 12:50 schrieb Gerd Hoffmann:

Quoted 5 lines

ui/input-linux.c | 7 +++++++ 1 file changed, 7 insertions(+)

ui/input-linux.c index renamed from ui/input-linux.c +0 -0

76a2abb..f884c00 100644 --- a/ui/input-linux.c +++

Quoted 9 lines

b/ui/input-linux.c @@ -257,6 +257,13 @@ static void input_linux_event_keyboard(void *opaque) */ continue; } +
if (event.code >= KEY_CNT) { + /* +
* Should not happen. But better safe than sorry, +
* and we make Coverity happy too. + */ +
continue; + } /* keep track of key state */ if
(!il->keydown[event.code] && event.value) { il->keydown[event.code] = true;

As it should not happen, I'd prefer this variant:

g_assert(event.code < KEY_CNT);

Regards,
Stefan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJW6UupAAoJEOCMIdVndFCtxc4QAJC9lsHMvJD2+o3k8F4MdqOx IG2YY3EOPH1EClTWQ2JX1QM+YD3nxXXHFLAOl9xYo9tQwoD1/JGTjRMdIBZgTN7u b5dLBBbAU+T/wEiEEVgBL2fACCoRFJtFTy9ZfbNe14jqsjbmArgXTpfnlQYJPbIa KpVwj1fFgc11nwgn9VkxYmXK4/wlXfIiV86rzcXOfRZ+nGtsdwJbFkbNkEqc3mxk q9155uo2u3Exqw+3NQNO+wqdmkEhuw1C2yrWGzCPUFHgiaHwatt2sTCW2S9uGvdH PYlcsnErlFApQS3EE9nRJ4Jpqh1+jdbN/NvvAiL+Fh/EEReqzVbcD+Ga24uZB0eF J/NgAEa6puPPjBnZ4CfnNGwd7sVfNhERULvso6EKTyn+eUqI6P3kl7VaiVAG7wpE rYDwCWSEHzhUK5cuLbxpF2lF1+1Z9VkYRw/8EUjxZSp32VMjODQHw2jrwBQCMtWn 3MTXc0nAVfPowzVxjhk9mqlRzXauzbPL1Y0b6d74CADmEAzpxsrsD+oTV1ljG6rA 0E8sJVHB1k7I5lWM98K4Jc/uJ/gcynE8hDI2lnLqtmvCp0V/yP02v0cblAZb3Ldn gDvEnQFoFgRGzm5ChXxAcMl9+CRScn9e94HzOTTJt3EEjQf9ifty4jEm7IxrNrd/ 5eWjDuoctw4ZexgMir5H
=EIex
-----END PGP SIGNATURE-----

#2 lore raw
Quoted 18 lines · Stefan Weil

Am 16.03.2016 um 12:50 schrieb Gerd Hoffmann:

Quoted 5 lines

ui/input-linux.c | 7 +++++++ 1 file changed, 7 insertions(+)

ui/input-linux.c index renamed from ui/input-linux.c +0 -0

76a2abb..f884c00 100644 --- a/ui/input-linux.c +++

Quoted 9 lines

b/ui/input-linux.c @@ -257,6 +257,13 @@ static void input_linux_event_keyboard(void *opaque) */ continue; } +
if (event.code >= KEY_CNT) { + /* +
* Should not happen. But better safe than sorry, +
* and we make Coverity happy too. + */ +
continue; + } /* keep track of key state */ if
(!il->keydown[event.code] && event.value) { il->keydown[event.code] = true;

As it should not happen, I'd prefer this variant:

Quoted 1 line

g_assert(event.code < KEY_CNT);

Well, it is highly unlikely but not impossible. KEY_CNT changed from 0x200 to 0x300 in kernel 2.6.28. If (a) this happens again and (b) a new key > 0x300 is pressed and (c) we didn't sync the linux headers yet so qemu still has the old KEY_CNT value we could hit this.

cheers,
Gerd