summaryrefslogtreecommitdiff
path: root/macros.h
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-02-03 21:51:42 +0000
committerDarkvater <darkvater@openttd.org>2006-02-03 21:51:42 +0000
commitc5a669b39f6a78ee3ed0b819dd9bc5985cbb2c18 (patch)
treee7d2444a0b7e457cba604a7704ce886eb0a61612 /macros.h
parent6dd2affaad238c40e36d29593c9e8217966355f2 (diff)
downloadopenttd-c5a669b39f6a78ee3ed0b819dd9bc5985cbb2c18.tar.xz
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Diffstat (limited to 'macros.h')
-rw-r--r--macros.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/macros.h b/macros.h
index e3192c8b3..75a365d63 100644
--- a/macros.h
+++ b/macros.h
@@ -142,14 +142,20 @@ static inline void swap_int32(int32 *a, int32 *b) { int32 t = *a; *a = *b; *b =
static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a = *b; *b = t; }
+static inline uint16 ReadLE16Aligned(const void* x)
+{
+ return FROM_LE16(*(const uint16*)x);
+}
-#if defined(TTD_LITTLE_ENDIAN)
-# define READ_LE_UINT16(b) (*(const uint16*)(b))
-#elif defined(TTD_BIG_ENDIAN)
- static inline uint16 READ_LE_UINT16(const void *b) {
- return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
- }
+static inline uint16 ReadLE16Unaligned(const void* x)
+{
+#ifdef OTTD_ALIGNMENT
+ return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
+#else
+ return FROM_LE16(*(const uint16*)x);
#endif
+}
+
/**
* ROtate x Left/Right by n (must be >= 0)