mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-27 12:40:13 +01:00
Fix off-by-one errors when dealing with *_MAX values.
LED_MAX, KEY_MAX, ABS_MT_MAX, etc. are all valid event codes Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
a8871e7aea
commit
b77fea9c89
6 changed files with 14 additions and 14 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue