qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: qemu-trivial@nongnu.org
Cc: jen@redhat.com, afaerber@suse.de, aliguori@amazon.com,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] qom: suppress conscan warning of returning null point
Date: Sat, 20 Sep 2014 08:11:41 +0800	[thread overview]
Message-ID: <1411171901-13792-1-git-send-email-akong@redhat.com> (raw)

Conscan complains about g_malloc0() and malloc() return null.

  Error: NULL_RETURNS (CWE-476):
  qemu-kvm/qom/object.c:239: returned_null: Function "g_malloc0(gsize)" returns null.
  qemu-kvm/qom/object.c:239: var_assigned: Assigning: "ti->class" = null return value from "g_malloc0(gsize)".
  qemu-kvm/qom/object.c:249: dereference: Dereferencing a null pointer "ti->class".

But if the passed size parameter is >= 1, then we can always get an
effective pointer, the warning disappears.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 qom/object.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index da0919a..0fbf2df 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -252,6 +252,7 @@ static void type_initialize(TypeImpl *ti)
     ti->class_size = type_class_get_size(ti);
     ti->instance_size = type_object_get_size(ti);
 
+    g_assert(ti->class_size != 0);
     ti->class = g_malloc0(ti->class_size);
 
     parent = type_get_parent(ti);
@@ -424,6 +425,7 @@ Object *object_new_with_type(Type type)
     g_assert(type != NULL);
     type_initialize(type);
 
+    g_assert(type->instance_size != 0);
     obj = g_malloc(type->instance_size);
     object_initialize_with_type(obj, type->instance_size, type);
     obj->free = g_free;
-- 
1.9.3

             reply	other threads:[~2014-09-20  0:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-20  0:11 Amos Kong [this message]
2014-09-20  2:41 ` [Qemu-devel] [PATCH] qom: suppress conscan warning of returning null point Gonglei (Arei)
2014-09-20  6:24 ` Paolo Bonzini
2014-09-22  6:35   ` Markus Armbruster

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=1411171901-13792-1-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=jen@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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).