summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Helsley <matt.helsley@gmail.com>2009-01-13 11:03:04 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-01-13 11:36:13 +1000
commit78c00bd77f983aa22611c9966fbcb7e22453b588 (patch)
tree4d9424dd923cbf4bbc5e93c39c5abd18b265d3af
parent760f1c6bb184e3b48ca6a6bfe8942d306f378148 (diff)
Fix FOO_MAX off-by-one
In linux/input.h each section's (e.g. ABS) FOO_MAX is the maximum FOO value. Recent kernels define FOO_CNT as the maximum number of FOO there will ever be. Hence using FOO_MAX to size the bit vectors representing the capabilities of an evdev device is off by one. Define FOO_CNT values for use with Linux kernels which lack them. Use FOO_CNT whenever we need to know the number of bits needed -- usually to calculate the number of longs needed. When iterating over the values FOO_MAX still seems appropriate however the loop test should include FOO_MAX rather than skip it. Signed-off-by: Matt Helsley <matt.helsley@gmail.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> (cherry picked from commit 4dfd86b2201b2b19761a1abb3c580cecf0060224) Conflicts: src/evdev.c
-rw-r--r--src/evdev.c24
-rw-r--r--src/evdev.h28
2 files changed, 34 insertions, 18 deletions
diff --git a/src/evdev.c b/src/evdev.c
index e48edd9..5601caa 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -236,7 +236,7 @@ static void
PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
{
int code = ev->code + MIN_KEYCODE;
- static char warned[KEY_MAX];
+ static char warned[KEY_CNT];
/* filter repeat events for chording keys */
if (value == 2 &&
@@ -248,7 +248,7 @@ PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
ev->code == KEY_SCROLLLOCK)) /* XXX windows keys? */
return;
- if (code > 255 && ev->code < KEY_MAX) {
+ if (code > 255 && ev->code <= KEY_MAX) {
if (!warned[ev->code])
xf86Msg(X_WARNING, "%s: unable to handle keycode %d\n",
pInfo->name, ev->code);
@@ -1202,12 +1202,12 @@ EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare)
int i;
char name[1024] = {0};
- long bitmask[NLONGS(EV_MAX)] = {0};
- long key_bitmask[NLONGS(KEY_MAX)] = {0};
- long rel_bitmask[NLONGS(REL_MAX)] = {0};
- long abs_bitmask[NLONGS(ABS_MAX)] = {0};
- long led_bitmask[NLONGS(LED_MAX)] = {0};
- struct input_absinfo absinfo[ABS_MAX];
+ long bitmask[NLONGS(EV_CNT)] = {0};
+ long key_bitmask[NLONGS(KEY_CNT)] = {0};
+ long rel_bitmask[NLONGS(REL_CNT)] = {0};
+ long abs_bitmask[NLONGS(ABS_CNT)] = {0};
+ long led_bitmask[NLONGS(LED_CNT)] = {0};
+ struct input_absinfo absinfo[ABS_CNT];
if (ioctl(pInfo->fd,
EVIOCGNAME(sizeof(name) - 1), name) < 0) {
@@ -1266,7 +1266,7 @@ EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare)
memset(absinfo, 0, sizeof(absinfo));
- for (i = 0; i < ABS_MAX; i++)
+ for (i = ABS_X; i <= ABS_MAX; i++)
{
if (TestBit(i, abs_bitmask))
{
@@ -1302,9 +1302,9 @@ error:
static int
EvdevProbe(InputInfoPtr pInfo)
{
- long key_bitmask[NLONGS(KEY_MAX)] = {0};
- long rel_bitmask[NLONGS(REL_MAX)] = {0};
- long abs_bitmask[NLONGS(ABS_MAX)] = {0};
+ long key_bitmask[NLONGS(KEY_CNT)] = {0};
+ long rel_bitmask[NLONGS(REL_CNT)] = {0};
+ long abs_bitmask[NLONGS(ABS_CNT)] = {0};
int i, has_axes, has_keys, num_buttons;
int kernel24 = 0;
EvdevPtr pEvdev = pInfo->private;
diff --git a/src/evdev.h b/src/evdev.h
index 107dc77..cdbc87d 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -40,6 +40,22 @@
#include <xkbstr.h>
#endif
+#ifndef EV_CNT /* linux 2.4 kernels and earlier lack _CNT defines */
+#define EV_CNT (EV_MAX+1)
+#endif
+#ifndef KEY_CNT
+#define KEY_CNT (KEY_MAX+1)
+#endif
+#ifndef REL_CNT
+#define REL_CNT (REL_MAX+1)
+#endif
+#ifndef ABS_CNT
+#define ABS_CNT (ABS_MAX+1)
+#endif
+#ifndef LED_CNT
+#define LED_CNT (LED_MAX+1)
+#endif
+
#define EVDEV_MAXBUTTONS 32
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
@@ -122,12 +138,12 @@ typedef struct {
/* Cached info from device. */
char name[1024];
- long bitmask[NLONGS(EV_MAX)];
- long key_bitmask[NLONGS(KEY_MAX)];
- long rel_bitmask[NLONGS(REL_MAX)];
- long abs_bitmask[NLONGS(ABS_MAX)];
- long led_bitmask[NLONGS(LED_MAX)];
- struct input_absinfo absinfo[ABS_MAX];
+ long bitmask[NLONGS(EV_CNT)];
+ long key_bitmask[NLONGS(KEY_CNT)];
+ long rel_bitmask[NLONGS(REL_CNT)];
+ long abs_bitmask[NLONGS(ABS_CNT)];
+ long led_bitmask[NLONGS(LED_CNT)];
+ struct input_absinfo absinfo[ABS_CNT];
/* minor/major number */
dev_t min_maj;