[PATCH] Xi: make the scope of len match its lifetime.

Tomas Carnecky tom at dbservice.com
Wed Dec 9 18:46:48 PST 2009


On 12/10/09 3:16 AM, Jamey Sharp wrote:
> The clang static analyzer gets confused by reusing the same variable.
>
> Reported-by: Tomas Carnecky<tom at dbservice.com>
> Signed-off-by: Jamey Sharp<jamey at minilop.net>
> ---
>
> What do you think of this patch in place of the "set len to zero to
> avoid confusing clang" patch? Does this also make clang happy? Am I the
> only one who'd prefer this approach over introducing a useless
> initialization? :-)

Actually, that one looks like a bug in clang. I mean, 'len' is clearly 
being assigned a value just before it's used. And I wouldn't want you to 
change code just to work around bugs in clang.

tom

>
> (Blue!)
>
>   Xi/xiquerydevice.c |   13 ++++++-------
>   1 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
> index 435868d..59edcf5 100644
> --- a/Xi/xiquerydevice.c
> +++ b/Xi/xiquerydevice.c
> @@ -428,7 +428,6 @@ ListDeviceClasses(ClientPtr client, DeviceIntPtr dev,
>   		  char *any, uint16_t *nclasses)
>   {
>       int total_len = 0;
> -    int len;
>       int i;
>       int rc;
>
> @@ -437,26 +436,26 @@ ListDeviceClasses(ClientPtr client, DeviceIntPtr dev,
>
>       if (dev->button)
>       {
> -        (*nclasses)++;
> -        len = ListButtonInfo(dev, (xXIButtonInfo*)any, rc == Success);
> +        int len = ListButtonInfo(dev, (xXIButtonInfo*)any, rc == Success);
>           any += len;
>           total_len += len;
> +        (*nclasses)++;
>       }

[snip]...



More information about the xorg-devel mailing list