From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG6Q4-0001q2-Mi for qemu-devel@nongnu.org; Tue, 27 Jan 2015 08:43:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YG6Pz-00019i-KC for qemu-devel@nongnu.org; Tue, 27 Jan 2015 08:43:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG6Pz-00019e-DM for qemu-devel@nongnu.org; Tue, 27 Jan 2015 08:42:59 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RDgwKP014995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 08:42:58 -0500 From: Markus Armbruster References: <1422361514-25226-1-git-send-email-armbru@redhat.com> <54C78C24.2030304@redhat.com> Date: Tue, 27 Jan 2015 14:42:56 +0100 In-Reply-To: <54C78C24.2030304@redhat.com> (Paolo Bonzini's message of "Tue, 27 Jan 2015 14:01:24 +0100") Message-ID: <87fvaw5ogv.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Paolo Bonzini 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.