git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix a bug in compat/bswap.h endianness detection

From
Ben Walton <bdwalton@gmail.com>
Date
May 30, 2014, 15:22 UTC
Message-ID
<1401463360-26972-1-git-send-email-bdwalton@gmail.com>

The changes to make detection of endianness more portable had a bug that breaks on (at least) Solaris x86. The bug appears to be a simple copy/paste typo. It checks for _BIG_ENDIAN and not _LITTLE_ENDIAN for both the case where we would decide the system is big endian and little endian. Instead, the second test should be for _LITTLE_ENDIAN and not _BIG_ENDIAN.

Two fixes were possible:
1. Change the negation order of the conditions in the second test.
2. Reverse the order of the conditions in the second test.

Use the second option so that the condition we expect is always a positive check.

Signed-off-by: Ben Walton <bdwalton@gmail.com>
---
I think that this should be applied to cb/byte-swap and re-merged
with next.
 compat/bswap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compat/bswap.h b/compat/bswap.h
index c4293db..f6fd9a6 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -120,7 +120,7 @@ static inline uint64_t git_bswap64(uint64_t x)
 
 # if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
 #  define GIT_BYTE_ORDER GIT_BIG_ENDIAN
-# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
+# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
 #  define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN
 # else
 #  error "Cannot determine endianness"
-- 
1.9.1
Next: Junio C Hamano
Message 1 of 2 in “Fix a bug in compat/bswap.h endianness detection”
  1. Fix a bug in compat/bswap.h endianness detectionBen Walton, May 30, 2014
  2. Junio C HamanoMay 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.