diff options
author | Darkvater <darkvater@openttd.org> | 2006-02-03 21:51:42 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-02-03 21:51:42 +0000 |
commit | c5a669b39f6a78ee3ed0b819dd9bc5985cbb2c18 (patch) | |
tree | e7d2444a0b7e457cba604a7704ce886eb0a61612 /macros.h | |
parent | 6dd2affaad238c40e36d29593c9e8217966355f2 (diff) | |
download | openttd-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.h | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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) |