qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result
@ 2014-06-17 17:57 Max Reitz
  2014-06-17 18:39 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Max Reitz @ 2014-06-17 17:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result
  2014-06-17 17:57 [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result Max Reitz
@ 2014-06-17 18:39 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2014-06-17 18:39 UTC (permalink / raw)
  To: Max Reitz, qemu-devel; +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 <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));
>                      }
> --

Please use a model like scripts/coverity-model.c to silence this and 
other errors.

Paolo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-17 18:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17 17:57 [Qemu-devel] [PATCH] qcow2: Silence covscan for g_realloc() result Max Reitz
2014-06-17 18:39 ` Paolo Bonzini

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).