From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bN01C-0005js-3Y for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:54:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bN017-0003f7-8l for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:54:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55807) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bN017-0003ep-0O for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:54:37 -0400 References: <1468306113-847-1-git-send-email-famz@redhat.com> From: Eric Blake Message-ID: <578512BB.3040003@redhat.com> Date: Tue, 12 Jul 2016 09:54:35 -0600 MIME-Version: 1.0 In-Reply-To: <1468306113-847-1-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="LsLwxHExXu07pC3lxXJumEORfoQfJP6Rj" Subject: Re: [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: Miroslav Rezanina , Peter Lieven , Stefan Hajnoczi , Max Reitz This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --LsLwxHExXu07pC3lxXJumEORfoQfJP6Rj From: Eric Blake To: Fam Zheng , qemu-devel@nongnu.org Cc: Miroslav Rezanina , Peter Lieven , Stefan Hajnoczi , Max Reitz Message-ID: <578512BB.3040003@redhat.com> Subject: Re: [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO References: <1468306113-847-1-git-send-email-famz@redhat.com> In-Reply-To: <1468306113-847-1-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/12/2016 12:48 AM, Fam Zheng wrote: > MIN_NON_ZERO(0, 1) is evaluated to 0. Rewrite the macro to fix it. Huh? Old expansion, in various stages: (((0) !=3D 0 && (0) < (1)) ? (0) : (1)) ((0 && 1) ? 0 : 1) (0 ? 0 : 1) 1 Maybe you meant MIN_NON_ZERO(1, 0), which evaluates to: (((1) !=3D 0 && (1) < (0)) ? (1) : (0)) ((1 && 0) ? 1 : 0) (0 ? 1 : 0) 0 in which case, you are correct that there is a bug. >=20 > Reported-by: Miroslav Rezanina > Signed-off-by: Fam Zheng > --- > include/qemu/osdep.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index e63da28..e4c6ae6 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -151,7 +151,8 @@ extern int daemon(int, int); > /* Minimum function that returns zero only iff both values are zero. > * Intended for use with unsigned values only. */ > #ifndef MIN_NON_ZERO > -#define MIN_NON_ZERO(a, b) (((a) !=3D 0 && (a) < (b)) ? (a) : (b)) > +#define MIN_NON_ZERO(a, b) ((a) =3D=3D 0 ? (b) : \ > + ((b) =3D=3D 0 ? (a) : (MIN(a, b)))) Another way might be: (!(a) =3D=3D !(b) ? MIN(a, b) : (a) + (b)) but you have to put more mental thought into that. I'm just fine with your version. With the commit message fixed, Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --LsLwxHExXu07pC3lxXJumEORfoQfJP6Rj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXhRK7AAoJEKeha0olJ0Nqg4sH/0416SIt0gyOBNX7/AnL7/7/ 1llO219bm1F788UoINHO8x1dL3DzCelzfNQj/pLpAobI3OBQL6kgUtpKR8d+LmU4 U8S0G3gTLcfE0MSMt8zUPKG45djiS5OB5fIXm6TEJkHxP9GLqK9BCl4CJpeg5x2V xbMNLT8Iukeh6HQ8Afge0SHGbq0+PGwldFpSD3zKmmuoXVTjXy+COzT0RAYXb3vy jKHPYpZVQg6WmRiguJACGF2dxLkvzcKbnt103ePm9SUqG/8ZcUikxRiHs0PSMU7y xmmdTFl9vs56QTsS0mfUv7C56vA0+SzLPMFqqnQUPeTZRwZqlv9m0946cIu7mNQ= =/W58 -----END PGP SIGNATURE----- --LsLwxHExXu07pC3lxXJumEORfoQfJP6Rj--