[PATCH libevdev 03/13] Rewrite libevdev_is_event_code to avoid signed/unsigned comparison

Peter Hutterer peter.hutterer at who-t.net
Sun Aug 25 16:27:23 PDT 2013


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 80dee1a..4daaa58 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -1005,10 +1005,13 @@ libevdev_is_event_type(const struct input_event *ev, unsigned int type)
 int
 libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code)
 {
-	return type < EV_MAX &&
-		ev->type == type &&
-		(type == EV_SYN || code <= libevdev_get_event_type_max(type)) &&
-		ev->code == code;
+	int max;
+
+	if (!libevdev_is_event_type(ev, type))
+		return 0;
+
+	max = libevdev_get_event_type_max(type);
+	return (max > -1 && code <= (unsigned int)max && ev->code == code);
 }
 
 const char*
-- 
1.8.2.1



More information about the Input-tools mailing list