From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG6nU-0007B7-Aj for qemu-devel@nongnu.org; Tue, 27 Jan 2015 09:07:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YG6nQ-00032I-8V for qemu-devel@nongnu.org; Tue, 27 Jan 2015 09:07:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG6nP-000320-Qn for qemu-devel@nongnu.org; Tue, 27 Jan 2015 09:07:12 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RE79Op003287 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 09:07:10 -0500 Date: Tue, 27 Jan 2015 15:07:07 +0100 From: Kevin Wolf Message-ID: <20150127140707.GD4624@noname.redhat.com> References: <1422361514-25226-1-git-send-email-armbru@redhat.com> <54C78C24.2030304@redhat.com> <87fvaw5ogv.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fvaw5ogv.fsf@blackfin.pond.sub.org> 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: Markus Armbruster Cc: Paolo Bonzini , qemu-devel@nongnu.org, stefanha@redhat.com Am 27.01.2015 um 14:42 hat Markus Armbruster geschrieben: > 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. 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