util: Fix MIN_NON_ZERO

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

Backports commit b6ece2c6f37926a994bc564a9e55ef3be6016d8f from qemu
This commit is contained in:
Fam Zheng 2018-02-23 14:09:35 -05:00 committed by Lioncash
parent 1781d5cfa6
commit 5c739f14f5
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -134,7 +134,8 @@
/* Minimum function that returns zero only iff both values are zero. /* Minimum function that returns zero only iff both values are zero.
* Intended for use with unsigned values only. */ * Intended for use with unsigned values only. */
#ifndef MIN_NON_ZERO #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 #endif
/* Round number down to multiple */ /* Round number down to multiple */