[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: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks |
Date: |
Tue, 27 Jan 2015 14:01:24 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
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;
}
Paolo