[Top][All Lists]

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

[Qemu-devel] [PATCH] build: Work around SIZE_MAX bug in OSX headers

From: Eric Blake
Subject: [Qemu-devel] [PATCH] build: Work around SIZE_MAX bug in OSX headers
Date: Tue, 12 Jul 2016 09:21:52 -0600

C99 requires SIZE_MAX to be declared with the same type as the
integral promotion of size_t, but OSX mistakenly defines it as
an unsigned long long expression even though size_t is only
unsigned long.  Rather than futzing around with whether size_t
is 32- or 64-bits wide, let the compiler get the right type
for us by virtue of integer promotion.

See also https://patchwork.ozlabs.org/patch/542327/ for an
instance where the wrong type trips us up if we don't fix it
for good in osdep.h.

Signed-off-by: Eric Blake <address@hidden>

I can't test this on OSX, but I _did_ test that if I remove the
'#ifdef __APPLE__' conditional (and just blindly do the redefine),
things still compile on Linux (which means I got the type
computation correct).

This is my response to

 include/qemu/osdep.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 7361006..9b4b2d3 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -141,6 +141,13 @@ extern int daemon(int, int);
 # error Unknown pointer size

+/* Mac OSX has a <stdint.h> bug that incorrectly defines SIZE_MAX with
+ * the wrong type */
+#ifdef __APPLE__
+#undef SIZE_MAX
+#define SIZE_MAX ((sizeof(char)) * -1)
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))

reply via email to

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