qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result
Date: Tue, 17 Jun 2014 19:57:54 +0200	[thread overview]
Message-ID: <1403027874-27274-1-git-send-email-mreitz@redhat.com> (raw)

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 <mreitz@redhat.com>
---
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));
                     }
-- 
2.0.0

             reply	other threads:[~2014-06-17 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-17 17:57 Max Reitz [this message]
2014-06-17 18:39 ` [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403027874-27274-1-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).