From: Kevin Wolf <kwolf@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks
Date: Tue, 27 Jan 2015 15:07:07 +0100 [thread overview]
Message-ID: <20150127140707.GD4624@noname.redhat.com> (raw)
In-Reply-To: <87fvaw5ogv.fsf@blackfin.pond.sub.org>
Am 27.01.2015 um 14:42 hat Markus Armbruster geschrieben:
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
> > On 27/01/2015 13:25, Markus Armbruster wrote:
> >> Unlike malloc(), g_try_malloc() & friends return a null pointer only
> >> on failure, never for a zero size. Simplify tests for failure
> >> accordingly. This helps Coverity see returned null pointers can't be
> >> dereferenced. Also makes the code easier to read.
> >
> > Unfortunately that's not what I see from the source:
> >
> > gpointer
> > g_try_malloc (gsize n_bytes)
> > {
> > gpointer mem;
> >
> > if (G_LIKELY (n_bytes))
> > mem = glib_mem_vtable.try_malloc (n_bytes);
> > else
> > mem = NULL;
> >
> > TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 0, 1));
> >
> > return mem;
> > }
>
> You're right. Brain fart, please ignore.
Should we consider introducing a qemu_try_malloc() that has the desired
behaviour? The (g_try_)malloc() interface is really easy to misuse and
I've messed up some error checks in the block layer myself.
Kevin
prev parent reply other threads:[~2015-01-27 14:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-27 12:25 [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks Markus Armbruster
2015-01-27 13:01 ` Paolo Bonzini
2015-01-27 13:42 ` Markus Armbruster
2015-01-27 14:07 ` Kevin Wolf [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=20150127140707.GD4624@noname.redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=pbonzini@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 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.