[PATCH libevdev 1/4] Fix off-by-one errors when dealing with *_MAX values.
Peter Hutterer
peter.hutterer at who-t.net
Thu Aug 29 18:06:37 PDT 2013
LED_MAX, KEY_MAX, ABS_MT_MAX, etc. are all valid event codes
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
libevdev/libevdev-uinput.c | 6 +++---
libevdev/libevdev.c | 10 +++++-----
test/test-common-uinput.c | 2 +-
test/test-event-names.c | 4 ++--
test/test-libevdev-has-event.c | 2 +-
test/test-uinput.c | 4 ++--
6 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
index c07fe0c..de2833e 100644
--- a/libevdev/libevdev-uinput.c
+++ b/libevdev/libevdev-uinput.c
@@ -60,7 +60,7 @@ set_evbits(const struct libevdev *dev, int fd, struct uinput_user_dev *uidev)
int rc = 0;
unsigned int type;
- for (type = 0; type < EV_MAX; type++) {
+ for (type = 0; type < EV_CNT; type++) {
unsigned int code;
int max;
int uinput_bit;
@@ -96,7 +96,7 @@ set_evbits(const struct libevdev *dev, int fd, struct uinput_user_dev *uidev)
goto out;
}
- for (code = 0; code < (unsigned int)max; code++) {
+ for (code = 0; code <= (unsigned int)max; code++) {
if (!libevdev_has_event_code(dev, type, code))
continue;
@@ -127,7 +127,7 @@ set_props(const struct libevdev *dev, int fd, struct uinput_user_dev *uidev)
unsigned int prop;
int rc = 0;
- for (prop = 0; prop < INPUT_PROP_MAX; prop++) {
+ for (prop = 0; prop <= INPUT_PROP_MAX; prop++) {
if (!libevdev_has_property(dev, prop))
continue;
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 95d041c..73405bc 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -312,7 +312,7 @@ sync_key_state(struct libevdev *dev)
if (rc < 0)
goto out;
- for (i = 0; i < KEY_MAX; i++) {
+ for (i = 0; i < KEY_CNT; i++) {
int old, new;
old = bit_is_set(dev->key_values, i);
new = bit_is_set(keystate, i);
@@ -366,7 +366,7 @@ sync_led_state(struct libevdev *dev)
if (rc < 0)
goto out;
- for (i = 0; i < LED_MAX; i++) {
+ for (i = 0; i < LED_CNT; i++) {
int old, new;
old = bit_is_set(dev->led_values, i);
new = bit_is_set(ledstate, i);
@@ -387,7 +387,7 @@ sync_abs_state(struct libevdev *dev)
int rc;
int i;
- for (i = ABS_X; i <= ABS_MAX; i++) {
+ for (i = ABS_X; i < ABS_CNT; i++) {
struct input_absinfo abs_info;
if (i >= ABS_MT_MIN && i <= ABS_MT_MAX)
@@ -423,7 +423,7 @@ sync_mt_state(struct libevdev *dev, int create_events)
int val[MAX_SLOTS];
} mt_state[ABS_MT_CNT];
- for (i = ABS_MT_MIN; i < ABS_MT_MAX; i++) {
+ for (i = ABS_MT_MIN; i <= ABS_MT_MAX; i++) {
int idx;
if (i == ABS_MT_SLOT)
continue;
@@ -447,7 +447,7 @@ sync_mt_state(struct libevdev *dev, int create_events)
init_event(dev, ev, EV_ABS, ABS_MT_SLOT, i);
}
- for (j = ABS_MT_MIN; j < ABS_MT_MAX; j++) {
+ for (j = ABS_MT_MIN; j <= ABS_MT_MAX; j++) {
int jdx = j - ABS_MT_MIN;
if (j == ABS_MT_SLOT)
diff --git a/test/test-common-uinput.c b/test/test-common-uinput.c
index 167d727..7f3fe1f 100644
--- a/test/test-common-uinput.c
+++ b/test/test-common-uinput.c
@@ -156,7 +156,7 @@ uinput_device_create(struct uinput_device* d)
/* write abs resolution now */
if (libevdev_has_event_type(d->d, EV_ABS)) {
int code;
- for (code = 0; code < ABS_MAX; code++) {
+ for (code = 0; code < ABS_CNT; code++) {
const struct input_absinfo *abs;
/* can't change slots */
diff --git a/test/test-event-names.c b/test/test-event-names.c
index 23a59e7..e31af6f 100644
--- a/test/test-event-names.c
+++ b/test/test-event-names.c
@@ -237,7 +237,7 @@ START_TEST(test_event_type)
ev.type = EV_REL;
ck_assert_int_eq(libevdev_is_event_type(&ev, EV_REL), 1);
- for (i = 0; i < EV_MAX; i++) {
+ for (i = 0; i < EV_CNT; i++) {
if (i == ev.type)
continue;
ck_assert_int_eq(libevdev_is_event_type(&ev, i), 0);
@@ -255,7 +255,7 @@ START_TEST(test_event_code)
ev.code = REL_Y;
ck_assert_int_eq(libevdev_is_event_code(&ev, EV_REL, REL_Y), 1);
- for (i = 0; i < EV_MAX; i++) {
+ for (i = 0; i < EV_CNT; i++) {
int j;
if (i == ev.type || i == EV_SYN)
continue;
diff --git a/test/test-libevdev-has-event.c b/test/test-libevdev-has-event.c
index d74c92e..ed10140 100644
--- a/test/test-libevdev-has-event.c
+++ b/test/test-libevdev-has-event.c
@@ -274,7 +274,7 @@ START_TEST(test_input_props)
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
- for (i = 0; i < INPUT_PROP_MAX; i++) {
+ for (i = 0; i < INPUT_PROP_CNT; i++) {
if (i == INPUT_PROP_DIRECT || i == INPUT_PROP_BUTTONPAD)
ck_assert_int_eq(libevdev_has_property(dev, i), 1);
else
diff --git a/test/test-uinput.c b/test/test-uinput.c
index a8f6cee..75e7fc0 100644
--- a/test/test-uinput.c
+++ b/test/test-uinput.c
@@ -63,7 +63,7 @@ START_TEST(test_uinput_create_device)
rc = libevdev_new_from_fd(fd, &dev2);
ck_assert_int_eq(rc, 0);
- for (type = 0; type < EV_MAX; type++) {
+ for (type = 0; type < EV_CNT; type++) {
int max = libevdev_get_event_type_max(type);
if (max == -1)
continue;
@@ -142,7 +142,7 @@ START_TEST(test_uinput_create_device_from_fd)
rc = libevdev_new_from_fd(fd2, &dev2);
ck_assert_int_eq(rc, 0);
- for (type = 0; type < EV_MAX; type++) {
+ for (type = 0; type < EV_CNT; type++) {
int max = libevdev_get_event_type_max(type);
if (max == -1)
continue;
--
1.8.2.1
More information about the Input-tools
mailing list