[libvirt] [PATCH] add an assert, to avoid a false-positive NULL-deref warning from clang

Jim Meyering jim at meyering.net
Mon Mar 1 17:56:51 UTC 2010


Eric Blake wrote:
> According to Jim Meyering on 3/1/2010 10:13 AM:
>> Here's a case in which using an assertion appears to be the only
>> way to tell clang that "client" really is non-NULL at that point.
>> I'm sure clang's analyzers will eventually improve, and hence avoid
>> this sort of false positive, so have marked this with a FIXME comment,
>> to help ensure we eventually remove this otherwise unnecessary assertion.
...
> On the other hand, perhaps a more invasive rewrite would also work while
> also avoiding assert(), by hoisting the worker->quitRequest into the while
> loop, something like:
>
>      while ((client = qemudPendingJob(server)) == NULL) {
>          if (worker->quitRequest
>              || virCondWait(&server->job, &server->lock) < 0) {
>              virMutexUnlock(&server->lock);
>              return NULL;
>          }
>      }
>      if (worker->quitRequest) {
>          virMutexUnlock(&client->lock);
>          virMutexUnlock(&server->lock);
>          return NULL;
>      }
>
> Should I write that into patch format?

Yes, please.
That is equivalent, placates clang, and is more readable.
Thanks!




More information about the libvir-list mailing list