From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkRIR-0003Pd-0M for qemu-devel@nongnu.org; Fri, 09 Oct 2015 02:36:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkRIM-0004bH-7D for qemu-devel@nongnu.org; Fri, 09 Oct 2015 02:36:50 -0400 References: <1444332916-16476-1-git-send-email-thuth@redhat.com> <1444332916-16476-5-git-send-email-thuth@redhat.com> <5616D0FF.5030909@redhat.com> From: Thomas Huth Message-ID: <56176079.3000900@redhat.com> Date: Fri, 9 Oct 2015 08:36:41 +0200 MIME-Version: 1.0 In-Reply-To: <5616D0FF.5030909@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 4/5] tests/i44fx-test: No need for zeroing memory before memset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek , qemu-devel@nongnu.org, Markus Armbruster Cc: qemu-trivial@nongnu.org On 08/10/15 22:24, Laszlo Ersek wrote: > On 10/08/15 21:35, Thomas Huth wrote: >> Change a g_malloc0 into g_malloc since the following >> memset fills the whole buffer anyway. >> >> Cc: Laszlo Ersek >> Signed-off-by: Thomas Huth >> --- >> tests/i440fx-test.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c >> index d0bc8de..7fa1709 100644 >> --- a/tests/i440fx-test.c >> +++ b/tests/i440fx-test.c >> @@ -191,7 +191,7 @@ static void write_area(uint32_t start, uint32_t end, uint8_t value) >> uint32_t size = end - start + 1; >> uint8_t *data; >> >> - data = g_malloc0(size); >> + data = g_malloc(size); >> memset(data, value, size); >> memwrite(start, data, size); >> >> > > Technically you are right of course, but I remember some historical mess > around this, in this file. > > Plus I vaguely recall g_new[0]() being the most recent preference. > > https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-new > > See e.g. commit 97f3ad3551. Markus? g_new IMHO only makes sense when you try to allocate the memory for a struct or something similar - for allocating byte arrays, g_malloc is the better choice. So I think this patch should be fine. Thomas