summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2016-07-12 14:48:33 +0800
committerMichael Roth <mdroth@linux.vnet.ibm.com>2016-08-05 16:03:16 -0500
commitb6ece2c6f37926a994bc564a9e55ef3be6016d8f (patch)
tree64c3c8c2f8aa33217140b41777416a9d852a13db
parent8d7d7764d59845b64c0dbffec33e186abfa89d83 (diff)
downloadqemu-b6ece2c6f37926a994bc564a9e55ef3be6016d8f.tar.gz
util: Fix MIN_NON_ZERO
MIN_NON_ZERO(1, 0) 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> Message-Id: <1468306113-847-1-git-send-email-famz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit d27ba624aa1dfe5c07cc01200d95967ffce905d9) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r--include/qemu/osdep.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 783270f132..94a16034ed 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -149,7 +149,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 */