[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error chec
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks |
Date: |
Tue, 27 Jan 2015 14:42:56 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Paolo Bonzini <address@hidden> 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.