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

Peter Hutterer peter.hutterer at who-t.net
Wed Dec 9 19:05:12 PST 2009


On Thu, Dec 10, 2009 at 03:46:48AM +0100, Tomas Carnecky wrote:
> 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.

I started looking at a few of the reported things and found them to be noisy
if not incorrect anyway. that's why I gave up after 'fixing' the three easy
ones, it wasn't worth the effort.
but since I had them already, I figured we might as well push them in.

Cheers,
  Peter

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