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

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



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;
+    if ( count > max )
     {
         elf_mark_broken(elf, "far too many section headers");
         count = max;



Attachment: libelf-use-UINT_MAX.patch
Description: Text document

_______________________________________________
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®.