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

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 28 18:22:21 PDT 2013


On Wed, Aug 28, 2013 at 10:43:04AM +0200, Benjamin Tissoires wrote:
> On Mon, Aug 26, 2013 at 1:27 AM, Peter Hutterer
> <peter.hutterer at who-t.net> wrote:
> > 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 &&
> 
> this should be at first type < EV_CNT, -> this is buggy also in
> libevdev_is_event_type().

fixed in libevev_is_event_type (separate patch), thanks.

> 
> > -               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);
> 
> max can not be < 0 here, as we already checked for type < EV_MAX in
> libevdev_is_event_type()

it can. so EV_MAX - 1 is a valid type (though currently undefined) and thus
has a max of -1. same for EV_FF_STATUS and EV_PWR, which don't have a max
defined atm.

> > +       return (max > -1 && code <= (unsigned int)max && ev->code == code);
> 
> So I would say that we can drop the test "max > -1" here. But it's up
> to you to decide.
> 
> In both cases:
> 
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

Thanks, I'll leave the check in :)

Cheers,
   Peter



More information about the Input-tools mailing list