[systemd-devel] [PATCH 3/5] [uninitialized] No need to check if num is < 0

David Herrmann dh.herrmann at gmail.com
Thu Sep 11 08:19:52 PDT 2014


Hi

On Wed, Sep 10, 2014 at 11:20 AM,  <philippedeswert at gmail.com> wrote:
> From: Philippe De Swert <philippedeswert at gmail.com>
>
> When num is < 0 we jump to the error handling. However at that time
> r is not set yet by keyboard_fill so we most likely get a nonsensical
> error. However the num check is not needed as the xkb_state_key_get_syms
> will not return negative values. From its documentation:
> @returns The number of keysyms in the syms_out array.  If no keysyms
>  are produced by the key in the given keyboard state, returns 0 and sets
>  syms_out to NULL.

I think it's totally legitimate for libxkbcommon to return -ENOMEM in
the future, in case a memory allocation is needed and fails. It's
unlikely, as the state should be pre-allocated to speed up runtime
keymap handling, but it's kinda nasty to silently ignore the error in
idev-keyboard.c

The "uninitialized value" warning for strerror() is right, though. I
fixed it by setting "r = num" before jumping to "error".

Thanks
David

> Found with coverity. Fixes: CID#1237784
>
> Signed-off-by: Philippe De Swert <philippedeswert at gmail.com>
> ---
>  src/libsystemd-terminal/idev-keyboard.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/src/libsystemd-terminal/idev-keyboard.c b/src/libsystemd-terminal/idev-keyboard.c
> index ab9e481..1eafbb1 100644
> --- a/src/libsystemd-terminal/idev-keyboard.c
> +++ b/src/libsystemd-terminal/idev-keyboard.c
> @@ -770,9 +770,6 @@ static int keyboard_feed_evdev(idev_keyboard *k, idev_data *data) {
>                  /* TODO: update LEDs */
>          }
>
> -        if (num < 0)
> -                goto error;
> -
>          r = keyboard_fill(k, &k->evdata, data->resync, ev->code, ev->value, num, keysyms);
>          if (r < 0)
>                  goto error;
> --
> 1.8.3.2
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list