#include <poll.h>
#include <sys/fcntl.h>
#include <search.h>
+#include <inttypes.h>
#include <linux/input.h>
#include <linux/hiddev.h>
typedef struct {
struct hiddev_field_info fi;
+ uint32_t maxusage;
int *lastvalues;
} HiddevField;
if (r) diee("%s: ioctl HIDIOCGFIELDINFO %#x %#x %#x", d->path,
f->fi.report_type, f->fi.report_id, f->fi.field_index);
- size_t sz= sizeof(*f->lastvalues) * f->fi.maxusage;
+ f->maxusage= f->fi.maxusage;
+
+ size_t sz= sizeof(*f->lastvalues) * f->maxusage;
f->lastvalues= mmalloc(sz);
memset(f->lastvalues,0,sz);
}
- assert(ur->usage_index < f->fi.maxusage);
+ if (ur->usage_index >= f->maxusage) {
+ uint32_t newmax= ur->usage_index + 1;
+ fprintf(stderr,"%s: usage_index %"PRIu32" >= maxusage %"PRIu32"\n",
+ d->path, ur->usage_index, f->maxusage);
+ f->lastvalues= mrealloc(f->lastvalues, sizeof(*f->lastvalues) * newmax);
+ memset(f->lastvalues + f->maxusage, 0,
+ sizeof(*f->lastvalues) * (newmax - f->maxusage));
+ f->maxusage= newmax;
+ }
return f;
}