[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



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.

>From ba26bad7aec8713ded0fd3300e951eac3673cc72 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Mon, 1 Mar 2010 15:19:48 +0100
Subject: [PATCH] add an assert, to avoid a false-positive NULL-deref warning from clang

* daemon/libvirtd.c (qemudWorker): Assert.
---
 daemon/libvirtd.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 9bdbecb..a357914 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -24,34 +24,35 @@
 #include <config.h>

 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/poll.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <netdb.h>
 #include <stdlib.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <assert.h>
 #include <stdarg.h>
 #include <syslog.h>
 #include <string.h>
 #include <errno.h>
 #include <getopt.h>
 #include <fnmatch.h>
 #include <grp.h>
 #include <signal.h>
 #include <netdb.h>

 #include "libvirt_internal.h"
 #include "virterror_internal.h"

 #define VIR_FROM_THIS VIR_FROM_QEMU

 #include "libvirtd.h"
 #include "dispatch.h"
@@ -1504,34 +1505,38 @@ static void *qemudWorker(void *data)
         virMutexLock(&server->lock);
         while (((client = qemudPendingJob(server)) == NULL) &&
                !worker->quitRequest) {
             if (virCondWait(&server->job, &server->lock) < 0) {
                 virMutexUnlock(&server->lock);
                 return NULL;
             }
         }
         if (worker->quitRequest) {
             if (client)
                 virMutexUnlock(&client->lock);
             virMutexUnlock(&server->lock);
             return NULL;
         }
         worker->processingCall = 1;
         virMutexUnlock(&server->lock);

+        /* Tell clang we know what we're doing.
+           FIXME: remove when clang improves.  */
+        assert (client);
+
         /* We own a locked client now... */
         client->refs++;

         /* Remove our message from dispatch queue while we use it */
         msg = qemudClientMessageQueueServe(&client->dx);

         /* This function drops the lock during dispatch,
          * and re-acquires it before returning */
         if (remoteDispatchClientRequest (server, client, msg) < 0) {
             VIR_FREE(msg);
             qemudDispatchClientFailure(client);
             client->refs--;
             virMutexUnlock(&client->lock);
             continue;
         }

         client->refs--;
--
1.7.0.1.414.g89213d


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]