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

Benjamin Tissoires benjamin.tissoires at gmail.com
Wed Aug 28 01:43:04 PDT 2013


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().

> -               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()

> +       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>

Cheers,
Benjamin

>  }
>
>  const char*
> --
> 1.8.2.1
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools


More information about the Input-tools mailing list