From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwyID-0006F8-Rb for qemu-devel@nongnu.org; Tue, 17 Jun 2014 14:39:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwyI4-0000zb-R0 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 14:39:37 -0400 Received: from mail-qc0-x232.google.com ([2607:f8b0:400d:c01::232]:44998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwyI4-0000zX-Lw for qemu-devel@nongnu.org; Tue, 17 Jun 2014 14:39:28 -0400 Received: by mail-qc0-f178.google.com with SMTP id c9so10268728qcz.37 for ; Tue, 17 Jun 2014 11:39:28 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <53A08B5C.1000202@redhat.com> Date: Tue, 17 Jun 2014 20:39:24 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1403027874-27274-1-git-send-email-mreitz@redhat.com> In-Reply-To: <1403027874-27274-1-git-send-email-mreitz@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi Il 17/06/2014 19:57, Max Reitz ha scritto: > g_realloc() returns NULL iff zero bytes are requested. Covscan therefore > reports a possible NULL pointer dereference, however, this is not > applicable here, as nb_clusters is guaranteed to be non-zero. > > In order to (hopefully) silence covscan, assert that the result of > g_realloc() is truly non-NULL. > > Signed-off-by: Max Reitz > --- > See https://bugzilla.redhat.com/show_bug.cgi?id=1102409 for covscan's > output. > --- > block/qcow2-refcount.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 9507aef..4b81077 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -1579,6 +1579,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, > nb_clusters = (new_offset >> s->cluster_bits) + 1; > refcount_table = g_realloc(refcount_table, > nb_clusters * sizeof(uint16_t)); > + assert(refcount_table); > memset(&refcount_table[old_nb_clusters], 0, (nb_clusters > - old_nb_clusters) * sizeof(uint16_t)); > } > -- Please use a model like scripts/coverity-model.c to silence this and other errors. Paolo