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

Re: [Xen-devel] [PATCH 2/4] libelf: use UINT_MAX



On Tue, Dec 06, 2016 at 04:52:12AM -0700, Jan Beulich wrote:
> While Xen indeed doesn't have limits.h, it still does have UINT_MAX, so
> we should avoid open coding it (and perhaps - even if unlikely -
> getting it wrong).
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> --- a/xen/common/libelf/libelf-private.h
> +++ b/xen/common/libelf/libelf-private.h
> @@ -43,6 +43,7 @@
>  #include <string.h>
>  #include <stddef.h>
>  #include <inttypes.h>
> +#include <limits.h>
>  #ifdef __sun__
>  #include <sys/byteorder.h>
>  #define bswap_16(x) BSWAP_16(x)
> --- a/xen/common/libelf/libelf-tools.c
> +++ b/xen/common/libelf/libelf-tools.c
> @@ -131,9 +131,10 @@ unsigned elf_shdr_count(struct elf_binar
>  {
>      unsigned count = elf_uval(elf, elf->ehdr, e_shnum);
>      uint64_t max = elf->size / sizeof(Elf32_Shdr);
> -    if (max > ~(unsigned)0)
> -        max = ~(unsigned)0; /* Xen doesn't have limits.h :-/ */
> -    if (count > max)
> +
> +    if ( max > UINT_MAX )
> +        max = UINT_MAX;

Can't you use a min helper here? It would be clear IMHO.

Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.