qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCHv4 1/4] util: introduce MIN_NON_ZERO


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCHv4 1/4] util: introduce MIN_NON_ZERO
Date: Wed, 22 Oct 2014 16:34:13 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 10/16/2014 01:54 AM, Peter Lieven wrote:
> at least in block layer we have the case of limits being defined for a
> BlockDriverState. However, in this context often zero (0) has the special
> meanining of undefined which means no limit. If two of those limits are
> combined and the minimum is needed the minimum function should only return
> zero if both parameters are zero.
> 
> Signed-off-by: Peter Lieven <address@hidden>
> ---
>  include/qemu/osdep.h |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 1565404..9a238df 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -68,6 +68,10 @@ typedef signed int              int_fast16_t;
>  #define MAX(a, b) (((a) > (b)) ? (a) : (b))
>  #endif
>  
> +#ifndef MIN_NON_ZERO
> +#define MIN_NON_ZERO(a, b) ((!!(a) && (a) < (b)) ? (a) : (b))

'(a) && expr' is already forcing the evaluation of (a) as a boolean;
thus rendering the '!!(a)' conversion to boolean redundant.

The patch is correct as is, so I'll leave a positive review, but if you
have a reason to respin, making it two characters shorter is probably
worth it.  Maybe it's also worth a comment that this macro is only
designed to work on unsigned values.

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]