summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Duncan Ogilvie2024-11-28 15:16:54 +0100
committerGravatar Duncan Ogilvie2024-11-28 15:16:54 +0100
commit8f24c4876a32b4f19e459bedd1fdbbc54cb0daa9 (patch)
tree4316563019acbd85e277422afe5b687959f2e940
parent3a1404c2e87daff1eb45c3f21182b7ede7a7a82b (diff)
downloadlibplist-8f24c4876a32b4f19e459bedd1fdbbc54cb0daa9.tar.gz
libplist-8f24c4876a32b4f19e459bedd1fdbbc54cb0daa9.tar.bz2
Switch from detecting little endian (common) to detecting big endian (rare)
This prevents a bug class where we bswap things when __LITTLE_ENDIAN__ is not defined. Almost all modern systems are little endian, so detecting __BIG_ENDIAN__ is a better strategy.
-rw-r--r--src/bplist.c12
-rw-r--r--src/plist.c18
2 files changed, 14 insertions, 16 deletions
diff --git a/src/bplist.c b/src/bplist.c
index 93f0bc6..1216974 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -168,15 +168,13 @@ union plist_uint_ptr
#define get_real_bytes(x) ((x) == (float) (x) ? sizeof(float) : sizeof(double))
-#if (defined(__LITTLE_ENDIAN__) \
- && !defined(__FLOAT_WORD_ORDER__)) \
- || (defined(__FLOAT_WORD_ORDER__) \
- && __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
-#define float_bswap64(x) bswap64(x)
-#define float_bswap32(x) bswap32(x)
-#else
+#if (defined(__BIG_ENDIAN__) && !defined(__FLOAT_WORD_ORDER__)) \
+ || (defined(__FLOAT_WORD_ORDER__) && __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
#define float_bswap64(x) (x)
#define float_bswap32(x) (x)
+#else
+#define float_bswap64(x) bswap64(x)
+#define float_bswap32(x) bswap32(x)
#endif
#ifndef __has_builtin
diff --git a/src/plist.c b/src/plist.c
index 79448db..0d4e077 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -82,26 +82,26 @@ static int plist_debug = 0;
#endif
#ifndef le16toh
-#ifdef __LITTLE_ENDIAN__
-#define le16toh(x) (x)
-#else
+#ifdef __BIG_ENDIAN__
#define le16toh(x) bswap16(x)
+#else
+#define le16toh(x) (x)
#endif
#endif
#ifndef le32toh
-#ifdef __LITTLE_ENDIAN__
-#define le32toh(x) (x)
-#else
+#ifdef __BIG_ENDIAN__
#define le32toh(x) bswap32(x)
+#else
+#define le32toh(x) (x)
#endif
#endif
#ifndef le64toh
-#ifdef __LITTLE_ENDIAN__
-#define le64toh(x) (x)
-#else
+#ifdef __BIG_ENDIAN__
#define le64toh(x) bswap64(x)
+#else
+#define le64toh(x) (x)
#endif
#endif