[PATCH 3/3] xkb: don't assign garbage value to led_return.

Jamey Sharp jamey at minilop.net
Wed Dec 9 17:26:43 PST 2009


On Wed, Dec 9, 2009 at 5:09 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> As the comment for the function states, led_return is undefined if map is
> NULL. We might as well skip writing to it then.

If you want to write to led_return only when the returned map is
non-null, then you need to move the assignment before the break
statement. The value of led is just as much garbage if the loop runs
to completion as it was when it hadn't been written to yet; just more
predictably so.

With that changed I'd give it a
Reviewed-by: Jamey Sharp <jamey at minilop.net>

because, well, why not?

> Found by clang.
>
> Reported-by: Tomas Carnecky <tom at dbservice.com>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  xkb/xkb.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/xkb/xkb.c b/xkb/xkb.c
> index 00ae29c..57bf5de 100644
> --- a/xkb/xkb.c
> +++ b/xkb/xkb.c
> @@ -3273,20 +3273,22 @@ _XkbFindNamedIndicatorMap(XkbSrvLedInfoPtr sli, Atom indicator,
>                           int *led_return)
>  {
>     XkbIndicatorMapPtr  map;
> -    int                 led;
>
>     /* search for the right indicator */
>     map = NULL;
>     if (sli->names && sli->maps) {
> +       int led;
> +
>        for (led = 0; (led < XkbNumIndicators) && (map == NULL); led++) {
>            if (sli->names[led] == indicator) {
>                map= &sli->maps[led];
>                break;
>            }
>        }
> +
> +       *led_return = led;
>     }
>
> -    *led_return = led;
>     return map;
>  }
>
> --
> 1.6.5.2
>
> _______________________________________________
> xorg-devel mailing list
> xorg-devel at lists.x.org
> http://lists.x.org/mailman/listinfo/xorg-devel
>


More information about the xorg-devel mailing list