summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-03-19 15:20:08 +0100
committerPeter Wu <peter@lekensteyn.nl>2014-03-19 15:20:08 +0100
commit4d7bfb1cce631b931d64b46c72990265b5122039 (patch)
treea0c9476cc7980169fb1a9b85c253997b6635ded0 /hw
parent198529586fff48da10e4c5d56c9a44db2b6a0a1d (diff)
downloadqemu-4d7bfb1cce631b931d64b46c72990265b5122039.tar.gz
unifying: ensure that report lengths are valid
The length should match our expectations, but let's check that to be sure. Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'hw')
-rw-r--r--hw/usb/hid-logitech-dj.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/hw/usb/hid-logitech-dj.c b/hw/usb/hid-logitech-dj.c
index c421b6639f..87291ae5b0 100644
--- a/hw/usb/hid-logitech-dj.c
+++ b/hw/usb/hid-logitech-dj.c
@@ -28,6 +28,8 @@
#include "hw/input/hid.h"
#include "hw/usb/hid-logitech-dj.h"
+#define COMPILE_ASSERT(cond) typedef char _compile_assert[1 - 2 * !(cond)]
+
/* Report IDs */
enum {
HIDPP_SHORT = 0x10, /* 7 bytes */
@@ -39,6 +41,11 @@ enum {
/* returns the expected length of the report or 0 if invalid */
static unsigned msg_report_length(HidppMsg *msg)
{
+ COMPILE_ASSERT(sizeof(HidppMsgShort) == 7);
+ COMPILE_ASSERT(sizeof(HidppMsgLong) == 20);
+ COMPILE_ASSERT(sizeof(DjMsgShort) == 15);
+ COMPILE_ASSERT(sizeof(DjMsgLong) == 32);
+
switch (msg->report_id) {
case HIDPP_SHORT: return 7;
case HIDPP_LONG: return 20;