From: "Andreas Färber" <afaerber@suse.de>
To: pbonzini@redhat.com
Cc: aliguori@us.ibm.com, Igor Mitsyanko <i.mitsyanko@samsung.com>,
alexander_barabash@mentor.com,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org, Igor Mammedov <imammedo@redhat.com>
Subject: Re: [Qemu-devel] [PATCH qom-next] qom: make object cast assert if NULL object is passed as argument
Date: Fri, 01 Jun 2012 11:57:25 +0200 [thread overview]
Message-ID: <4FC89205.80400@suse.de> (raw)
In-Reply-To: <m3k3zswy4r.fsf@blackfin.pond.sub.org>
Am 31.05.2012 10:30, schrieb Markus Armbruster:
> Igor Mitsyanko <i.mitsyanko@samsung.com> writes:
>
>> On 05/30/2012 08:19 PM, Igor Mammedov wrote:
>>> without assert it will crash at following point:
>>> OBJECT_CHECK(type, obj, name) \
>>> ((type *)object_dynamic_cast_assert(OBJECT(obj), (name)))
>>> => object_dynamic_cast(obj, typename)
>>> => object_is_type(obj, target_type)
>>> => type_is_ancestor(obj->class->type, target_type);
>>> ^^^
>>> so abort earlier and print nice message instead of SIGSEGV
>>>
>>> Signed-off-by: Igor Mammedov<imammedo@redhat.com>
>>> ---
>>> qom/object.c | 2 ++
>>> 1 files changed, 2 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/qom/object.c b/qom/object.c
>>> index 00bb3b0..444e2fc 100644
>>> --- a/qom/object.c
>>> +++ b/qom/object.c
>>> @@ -481,6 +481,8 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename)
>>> {
>>> Object *inst;
>>>
>>> + g_assert(obj != NULL);
>>> +
>>> inst = object_dynamic_cast(obj, typename);
>>>
>>> if (!inst) {
>> Makes much sense, but maybe it should be done in OBJECT() cast? Assert
>> when we do OBJECT(NULL).
>
> In my opinion, OBJECT(p) where p is a null pointer is perfectly valid
> and should yield a null pointer.
Paolo, today OBJECT(p) is a pure C cast. I wonder if that was due to
TYPE_OBJECT being NULL at the time. Should we reconsider that on
qom-next with your patches to turn TYPE_OBJECT into a regular type?
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
prev parent reply other threads:[~2012-06-01 9:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1338394747-17427-1-git-send-email-imammedo@redhat.com>
[not found] ` <4FC6533C.3010207@samsung.com>
[not found] ` <m3k3zswy4r.fsf@blackfin.pond.sub.org>
[not found] ` <4FC744FE.3030203@redhat.com>
[not found] ` <4FC7533B.2060102@redhat.com>
2012-06-01 9:52 ` [Qemu-devel] [PATCH qom-next] qom: make object cast assert if NULL object is passed as argument Andreas Färber
2012-06-01 11:18 ` Markus Armbruster
2012-06-01 13:04 ` Andreas Färber
2012-06-04 7:39 ` Markus Armbruster
2012-06-04 13:14 ` Igor Mammedov
2012-06-01 9:57 ` Andreas Färber [this message]
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=4FC89205.80400@suse.de \
--to=afaerber@suse.de \
--cc=alexander_barabash@mentor.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=i.mitsyanko@samsung.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@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).