All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: jen@redhat.com, qemu-trivial@nongnu.org, qemu-devel@nongnu.org,
	aliguori@amazon.com, afaerber@suse.de
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] qom: suppress conscan warning of returning null point
Date: Mon, 22 Sep 2014 08:35:18 +0200	[thread overview]
Message-ID: <87lhpcw4bd.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <541D1D9A.6020100@redhat.com> (Paolo Bonzini's message of "Sat, 20 Sep 2014 08:24:26 +0200")

Paolo Bonzini <pbonzini@redhat.com> writes:

> Il 20/09/2014 02:11, Amos Kong ha scritto:
>> Conscan complains about g_malloc0() and malloc() return null.

s/Conscan/Coverity/, both here and in subject.

>> 
>>   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.
>
> The model should handle it:
>
> void *
> g_malloc0(size_t n_bytes)
> {
>     void *mem;
>     __coverity_negative_sink__(n_bytes);
>     mem = calloc(1, n_bytes == 0 ? 1 : n_bytes);
>     if (!mem) __coverity_panic__();
>     return mem;
> }
>
> So this patch means your coverity runs are misconfigured.

Yes.  I'm not sure we want the assertions anyway.

I use the following options with cov-analyze:

    -co BAD_FREE:allow_first_field:true
    -co DEADCODE:no_dead_default:true
    --security
    --concurrency
    --user-model-file scripts/coverity-model.xmldb
    --derived-model-file ~/work/glib/glib-2.38.2.xmldb

where glib-2.38.2.xmldb is produced by "cov-collect-models --dir cov -of
glib-2.32.4.xmldb" after a full Coverity scan of glib.


WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: jen@redhat.com, qemu-trivial@nongnu.org, qemu-devel@nongnu.org,
	aliguori@amazon.com, Amos Kong <akong@redhat.com>,
	afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH] qom: suppress conscan warning of returning null point
Date: Mon, 22 Sep 2014 08:35:18 +0200	[thread overview]
Message-ID: <87lhpcw4bd.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <541D1D9A.6020100@redhat.com> (Paolo Bonzini's message of "Sat, 20 Sep 2014 08:24:26 +0200")

Paolo Bonzini <pbonzini@redhat.com> writes:

> Il 20/09/2014 02:11, Amos Kong ha scritto:
>> Conscan complains about g_malloc0() and malloc() return null.

s/Conscan/Coverity/, both here and in subject.

>> 
>>   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.
>
> The model should handle it:
>
> void *
> g_malloc0(size_t n_bytes)
> {
>     void *mem;
>     __coverity_negative_sink__(n_bytes);
>     mem = calloc(1, n_bytes == 0 ? 1 : n_bytes);
>     if (!mem) __coverity_panic__();
>     return mem;
> }
>
> So this patch means your coverity runs are misconfigured.

Yes.  I'm not sure we want the assertions anyway.

I use the following options with cov-analyze:

    -co BAD_FREE:allow_first_field:true
    -co DEADCODE:no_dead_default:true
    --security
    --concurrency
    --user-model-file scripts/coverity-model.xmldb
    --derived-model-file ~/work/glib/glib-2.38.2.xmldb

where glib-2.38.2.xmldb is produced by "cov-collect-models --dir cov -of
glib-2.32.4.xmldb" after a full Coverity scan of glib.

  reply	other threads:[~2014-09-22  6:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-20  0:11 [Qemu-trivial] [PATCH] qom: suppress conscan warning of returning null point Amos Kong
2014-09-20  0:11 ` [Qemu-devel] " Amos Kong
2014-09-20  2:41 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-20  2:41   ` Gonglei (Arei)
2014-09-20  6:24 ` [Qemu-trivial] " Paolo Bonzini
2014-09-20  6:24   ` [Qemu-devel] " Paolo Bonzini
2014-09-22  6:35   ` Markus Armbruster [this message]
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=87lhpcw4bd.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=jen@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.