qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO
@ 2016-07-12  6:48 Fam Zheng
  2016-07-12 15:54 ` Eric Blake
  2016-07-14 12:17 ` Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Fam Zheng @ 2016-07-12  6:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Lieven, famz, Miroslav Rezanina, Max Reitz, Stefan Hajnoczi

MIN_NON_ZERO(0, 1) is evaluated to 0. Rewrite the macro to fix it.

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))))
 #endif
 
 /* Round number down to multiple */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-18  8:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-12  6:48 [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO Fam Zheng
2016-07-12 15:54 ` Eric Blake
2016-07-12 16:24   ` Paolo Bonzini
2016-07-18  8:00     ` Peter Lieven
2016-07-14 12:17 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).