From: Eric Blake <eblake@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: Miroslav Rezanina <mrezanin@redhat.com>,
Peter Lieven <pl@kamp.de>, Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO
Date: Tue, 12 Jul 2016 09:54:35 -0600 [thread overview]
Message-ID: <578512BB.3040003@redhat.com> (raw)
In-Reply-To: <1468306113-847-1-git-send-email-famz@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1519 bytes --]
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) != 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) != 0 && (1) < (0)) ? (1) : (0))
((1 && 0) ? 1 : 0)
(0 ? 1 : 0)
0
in which case, you are correct that there is a bug.
>
> Reported-by: Miroslav Rezanina <mrezanin@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> include/qemu/osdep.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> 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) != 0 && (a) < (b)) ? (a) : (b))
> +#define MIN_NON_ZERO(a, b) ((a) == 0 ? (b) : \
> + ((b) == 0 ? (a) : (MIN(a, b))))
Another way might be:
(!(a) == !(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 <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-07-12 15:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 6:48 [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO Fam Zheng
2016-07-12 15:54 ` Eric Blake [this message]
2016-07-12 16:24 ` Paolo Bonzini
2016-07-18 8:00 ` Peter Lieven
2016-07-14 12:17 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=578512BB.3040003@redhat.com \
--to=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=mreitz@redhat.com \
--cc=mrezanin@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.