From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9yNr-0002XR-7d for qemu-devel@nongnu.org; Fri, 29 May 2009 05:28:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9yNl-0002SG-Hj for qemu-devel@nongnu.org; Fri, 29 May 2009 05:28:13 -0400 Received: from [199.232.76.173] (port=52504 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9yNl-0002SC-8D for qemu-devel@nongnu.org; Fri, 29 May 2009 05:28:09 -0400 Received: from srv-05.w4a.fr ([94.23.5.116]:45305 helo=mx1.w4a.fr) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9yNk-0001OY-So for qemu-devel@nongnu.org; Fri, 29 May 2009 05:28:09 -0400 Date: Fri, 29 May 2009 10:28:03 +0100 (GMT+01:00) From: jcd@tribudubois.net Message-ID: <20380459.68691243589283394.JavaMail.root@srv-05.w4a.fr> In-Reply-To: <4A1F9FFE.3030100@redhat.com> Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org Hi Kevin, Thanks for pointing this. I guess it just sounds strange to me that somebod= y would want to alloc 0 bytes. But why not ... I guess that if pattern_count/count is set to 0 we can just avoid the all p= rocessing of malloc/memset/memcmp/free anyway. Would you be ok with something like: if (Pflag && pattern_count) { instead of:=20 if (Pflag) { JC ----- Mail Original ----- De: "Kevin Wolf" =C3=80: "Jean-Christophe Dubois" Cc: qemu-devel@nongnu.org, "malc" Envoy=C3=A9: Vendredi 29 Mai 2009 10h42:38 GMT +01:00 Amsterdam / Berlin / = Berne / Rome / Stockholm / Vienne Objet: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently Jean-Christophe Dubois schrieb: > qemu_malloc, qemu_free and friends are not used consistently in the qemu= =20 > source code. >=20 > This is a first attempt to use these oveloaded functions consistently all= over=20 > the place instead of the default glibc versions. >=20 > Signed-off-by: Jean-Christophe DUBOIS [...] > diff -rNu qemu.org/qemu-io.c qemu/qemu-io.c > --- qemu.org/qemu-io.c=092009-05-16 17:57:27.000000000 +0200 > +++ qemu/qemu-io.c=092009-05-18 23:48:23.000000000 +0200 > @@ -311,14 +311,14 @@ > =09} > =20 > =09if (Pflag) { > -=09=09void* cmp_buf =3D malloc(pattern_count); > +=09=09void* cmp_buf =3D qemu_malloc(pattern_count); > =09=09memset(cmp_buf, pattern, pattern_count); > =09=09if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) { > =09=09=09printf("Pattern verification failed at offset %lld, " > =09=09=09=09"%d bytes\n", > =09=09=09=09(long long) offset + pattern_offset, pattern_count); > =09=09} > -=09=09free(cmp_buf); > +=09=09qemu_free(cmp_buf); > =09} > =20 > =09if (qflag) > @@ -465,14 +465,14 @@ > =09} > =20 > =09if (Pflag) { > -=09=09void* cmp_buf =3D malloc(count); > +=09=09void* cmp_buf =3D qemu_malloc(count); > =09=09memset(cmp_buf, pattern, count); > =09=09if (memcmp(buf, cmp_buf, count)) { > =09=09=09printf("Pattern verification failed at offset %lld, " > =09=09=09=09"%d bytes\n", > =09=09=09=09(long long) offset, count); > =09=09} > -=09=09free(cmp_buf); > +=09=09qemu_free(cmp_buf); > =09} > =20 > =09if (qflag) Since recently qemu_malloc behaves differently from malloc with size =3D 0. This isn't allowed any more with qemu_malloc. So you need to check for pattern_count =3D=3D 0 and either print an error message or malloc a different size, e.g. 1. I'm sure we don't want qemu-io to abort() in such a case. Or we could start over with a lengthy discussion about fixing qemu_malloc..= . Kevin