From 4d7bfb1cce631b931d64b46c72990265b5122039 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 19 Mar 2014 15:20:08 +0100 Subject: 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 --- hw/usb/hid-logitech-dj.c | 7 +++++++ 1 file changed, 7 insertions(+) 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; -- cgit v1.2.1