@@ -40,18 +40,19 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4040//
4141
4242#ifndef FIELD_OFFSET
43- #define FIELD_OFFSET (type, field ) ((LONG)(LONG_PTR )&(((type *)0 )->field))
43+ #define FIELD_OFFSET (type, field ) ((LONG)(intptr_t )&(((type *)0 )->field))
4444#endif
4545
4646typedef char CHAR;
4747typedef unsigned short WCHAR;
4848
4949typedef unsigned char BYTE;
5050typedef unsigned short WORD;
51- typedef unsigned long DWORD;
5251
53- typedef long *LONG_PTR;
54- typedef long LONG;
52+ // FG-2014-09-17: [[ Bugfix 13463 ]] "long" is 64 bits on Linux x86_64
53+ typedef uint32_t DWORD;
54+ typedef int32_t LONG;
55+
5556
5657#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
5758#define IMAGE_OS2_SIGNATURE 0x454E // NE
@@ -542,7 +543,7 @@ static inline void swap_dword(DWORD& x)
542543#endif
543544}
544545
545- static inline void swap_long (long & x)
546+ static inline void swap_long (LONG & x)
546547{
547548#ifdef __BIG_ENDIAN__
548549 uint32_t y;
@@ -638,9 +639,16 @@ struct MCWindowsResources
638639 bool is_table;
639640 union
640641 {
641- struct
642+ // FG-2014-09-17: [[ Bugfix 13463 ]]
643+ // The members of this union should be aligned with similarly-sized
644+ // fields in order to prevent issues on 64-bit systems (in particular,
645+ // a bool should not be lined up with a pointer as compilers are allowed
646+ // to write anything they like into the high-order bytes).
647+ struct
642648 {
643649 uint32_t entry_count;
650+ uint32_t _pad_codepage; // PADDING
651+ bool _pad_in_file; // PADDING
644652 MCWindowsResources *entries;
645653 } table;
646654
@@ -1091,7 +1099,9 @@ static bool add_version_info_entry(void *p_context, MCArrayRef p_array, MCNameRe
10911099 byte_t *t_bytes;
10921100 uindex_t t_byte_count;
10931101 /* UNCHECKED */ MCStringConvertToBytes (*t_value, kMCStringEncodingUTF16LE , false , t_bytes, t_byte_count);
1094- if (t_bytes[t_byte_count - 1 ] != ' \0 ' || t_bytes[t_byte_count - 2 ] != ' \0 ' )
1102+
1103+ // FG-2014-09-17: [[ Bugfix 13463 ]] Convert may return 0 bytes for the empty string
1104+ if (t_byte_count == 0 || t_bytes[t_byte_count - 1 ] != ' \0 ' || t_bytes[t_byte_count - 2 ] != ' \0 ' )
10951105 {
10961106 byte_t * temp = t_bytes;
10971107 t_bytes = new byte_t [t_byte_count + 2 ];
0 commit comments