git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Ensure __BYTE_ORDER is always set
@ 2014-01-30 19:55 Brian Gernhardt
  2014-01-30 20:45 ` Jeff King
  2014-01-30 22:02 ` Jonathan Nieder
  0 siblings, 2 replies; 9+ messages in thread
From: Brian Gernhardt @ 2014-01-30 19:55 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

a201c20 (ewah: support platforms that require aligned reads) added a
reliance on the existence of __BYTE_ORDER and __BIG_ENDIAN.  However,
these macros are spelled without the leading __ on some platforms (OS
X at least).  In this case, the endian-swapping code was added even
when unnecessary, which caused assertion failures in
t5310-pack-bitmaps.sh as the code that used the bitmap would read past
the end.

We already had code to handle this case in compat/bswap.h, but it was
only used if we couldn't already find a reasonable version of bswap64.
Move the macro-defining and checking code out of a conditional so that
either __BYTE_ORDER is defined or we get a compilation error instead
of a runtime error in the bitmap code.

Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
 compat/bswap.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/compat/bswap.h b/compat/bswap.h
index 120c6c1..7db09d6 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -80,6 +80,18 @@ static inline uint64_t git_bswap64(uint64_t x)
 
 #endif
 
+#if !defined(__BYTE_ORDER)
+# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
+#  define __BYTE_ORDER BYTE_ORDER
+#  define __LITTLE_ENDIAN LITTLE_ENDIAN
+#  define __BIG_ENDIAN BIG_ENDIAN
+# endif
+#endif
+
+#if !defined(__BYTE_ORDER)
+# error "Cannot determine endianness"
+#endif
+
 #if defined(bswap32)
 
 #undef ntohl
@@ -101,18 +113,6 @@ static inline uint64_t git_bswap64(uint64_t x)
 #undef ntohll
 #undef htonll
 
-#if !defined(__BYTE_ORDER)
-# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
-#  define __BYTE_ORDER BYTE_ORDER
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-#  define __BIG_ENDIAN BIG_ENDIAN
-# endif
-#endif
-
-#if !defined(__BYTE_ORDER)
-# error "Cannot determine endianness"
-#endif
-
 #if __BYTE_ORDER == __BIG_ENDIAN
 # define ntohll(n) (n)
 # define htonll(n) (n)
-- 
1.9.rc0.256.gbc3fa69

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-01-31  2:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-30 19:55 [PATCH] Ensure __BYTE_ORDER is always set Brian Gernhardt
2014-01-30 20:45 ` Jeff King
2014-01-30 21:50   ` Jeff King
2014-01-31  2:35     ` Eric Sunshine
2014-01-30 22:12   ` Jonathan Nieder
2014-01-30 22:48     ` Jeff King
2014-01-30 23:24   ` Brian Gernhardt
2014-01-30 22:02 ` Jonathan Nieder
2014-01-30 22:46   ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).