Changeset - r2966:4803bfe02c27
[Not reviewed]
master
0 5 0
Darkvater - 18 years ago 2006-02-03 21:51:42
darkvater@openttd.org
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
5 files changed with 29 insertions and 24 deletions:
0 comments (0 inline, 0 general)
gfx.c
Show inline comments
 
@@ -695,13 +695,13 @@ static void GfxBlitTileZoomIn(BlitterPar
 
	int num, skip;
 
	byte done;
 
	Pixel *dst;
 
	const byte* ctab;
 

	
 
	if (bp->mode & 1) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 

	
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
@@ -738,13 +738,13 @@ static void GfxBlitTileZoomIn(BlitterPar
 
				for (; num != 0; num--) *dst++ = ctab[*src++];
 
			} while (!(done & 0x80));
 

	
 
			bp->dst += bp->pitch;
 
		} while (--bp->height != 0);
 
	} else if (bp->mode & 2) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src_o += num + 2;
 
@@ -772,13 +772,13 @@ static void GfxBlitTileZoomIn(BlitterPar
 
				}
 
			} while (!(done & 0x80));
 

	
 
			bp->dst += bp->pitch;
 
		} while (--bp->height != 0);
 
	} else {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src = src_o + 2;
 
@@ -897,13 +897,13 @@ static void GfxBlitTileZoomMedium(Blitte
 
	int num, skip;
 
	byte done;
 
	Pixel *dst;
 
	const byte* ctab;
 

	
 
	if (bp->mode & 1) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src = src_o + 2;
 
@@ -946,13 +946,13 @@ static void GfxBlitTileZoomMedium(Blitte
 
			do {
 
				done = src_o[0];
 
				src_o += (done & 0x7F) + 2;
 
			} while (!(done & 0x80));
 
		} while (--bp->height != 0);
 
	} else if (bp->mode & 2) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src_o += num + 2;
 
@@ -991,13 +991,13 @@ static void GfxBlitTileZoomMedium(Blitte
 
			do {
 
				done = src_o[0];
 
				src_o += (done & 0x7F) + 2;
 
			} while (!(done & 0x80));
 
		} while (--bp->height != 0);
 
	} else {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		do {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src = src_o + 2;
 
@@ -1102,13 +1102,13 @@ static void GfxBlitTileZoomOut(BlitterPa
 
	int num, skip;
 
	byte done;
 
	Pixel *dst;
 
	const byte* ctab;
 

	
 
	if (bp->mode & 1) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		for (;;) {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src = src_o + 2;
 
@@ -1171,13 +1171,13 @@ static void GfxBlitTileZoomOut(BlitterPa
 
				done = src_o[0];
 
				src_o += (done & 0x7F) + 2;
 
			} while (!(done & 0x80));
 
			if (--bp->height == 0) return;
 
		}
 
	} else if (bp->mode & 2) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		for (;;) {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src_o += num + 2;
 
@@ -1236,13 +1236,13 @@ static void GfxBlitTileZoomOut(BlitterPa
 
				done = src_o[0];
 
				src_o += (done & 0x7F) + 2;
 
			} while (!(done & 0x80));
 
			if (--bp->height == 0) return;
 
		}
 
	} else {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		src_o += ReadLE16Aligned(src_o + bp->start_y * 2);
 
		for (;;) {
 
			do {
 
				done = src_o[0];
 
				num = done & 0x7F;
 
				skip = src_o[1];
 
				src = src_o + 2;
macros.h
Show inline comments
 
@@ -139,20 +139,26 @@ static inline void swap_byte(byte *a, by
 
static inline void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; }
 
static inline void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; }
 
static inline void swap_int32(int32 *a, int32 *b) { int32 t = *a; *a = *b; *b = t; }
 
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)
 
 * @note Assumes a byte has 8 bits
 
 */
 
#define ROL(x, n) ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
smallmap_gui.c
Show inline comments
 
@@ -191,13 +191,13 @@ static const uint16 * const _legend_tabl
 
	_legend_industries_normal,
 
	_legend_industries_hilly,
 
	_legend_industries_desert,
 
	_legend_industries_candy,
 
};
 

	
 
#if defined(TTD_ALIGNMENT_4)
 
#if defined(OTTD_ALIGNMENT)
 
	static inline void WRITE_PIXELS(Pixel* d, uint32 val)
 
	{
 
#	if defined(TTD_BIG_ENDIAN)
 
		d[0] = GB(val, 24, 8);
 
		d[1] = GB(val, 16, 8);
 
		d[2] = GB(val,  8, 8);
stdafx.h
Show inline comments
 
@@ -79,14 +79,12 @@
 
#if defined(__WATCOMC__)
 
# define NORETURN
 
# define FORCEINLINE inline
 
# define CDECL
 
# define NOT_REACHED() assert(0)
 
# define GCC_PACK
 
# undef TTD_ALIGNMENT_4
 
# undef TTD_ALIGNMENT_2
 
# include <malloc.h>
 
#endif /* __WATCOMC__ */
 

	
 
#if defined(__MINGW32__) || defined(__CYGWIN__)
 
# include <malloc.h> // alloca()
 
#endif
 
@@ -130,14 +128,12 @@
 
    typedef __int64 intptr_t;
 
#  else
 
    typedef _W64 int intptr_t;
 
#  endif
 
# endif /* _MSC_VER < 1300 */
 

	
 
# undef TTD_ALIGNMENT_4
 
# undef TTD_ALIGNMENT_2
 
# define GCC_PACK
 

	
 
// This is needed to zlib uses the stdcall calling convention on visual studio, also used with libpng (VS6 warning)
 
# if defined(WITH_ZLIB) || defined(WITH_PNG)
 
#  ifndef ZLIB_WINAPI
 
#   define ZLIB_WINAPI
 
@@ -190,16 +186,19 @@ typedef unsigned char byte;
 
   typedef unsigned char bool;
 
# endif
 
  typedef signed __int64 int64;
 
  typedef unsigned __int64 uint64;
 
#endif /* __BEOS__ */
 

	
 
#if defined(ARM) || defined(__arm__)
 
# define OTTD_ALIGNMENT
 
#endif
 

	
 
// Setup alignment and conversion macros
 
#if defined(TTD_BIG_ENDIAN)
 
# define TTD_ALIGNMENT_2
 
# define TTD_ALIGNMENT_4
 
#	define OTTD_ALIGNMENT
 
  static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); }
 
  static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); }
 
  static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
 
  static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
 
# define TO_BE32(x) (x)
 
# define TO_BE16(x) (x)
strings.c
Show inline comments
 
@@ -497,13 +497,13 @@ static char *FormatString(char *buff, co
 
			*buff++ = b;
 
			*buff++ = *str++;
 
			*buff++ = *str++;
 
			break;
 

	
 
		case 0x81: // {STRINL}
 
			buff = GetStringWithArgs(buff, READ_LE_UINT16(str), argv);
 
			buff = GetStringWithArgs(buff, ReadLE16Unaligned(str), argv);
 
			str += 2;
 
			break;
 
		case 0x82: // {DATE_LONG}
 
			buff = FormatYmdString(buff, GetInt32(&argv));
 
			break;
 
		case 0x83: // {DATE_SHORT}
 
@@ -1012,13 +1012,13 @@ bool ReadLanguagePack(int lang_index)
 
		free(lang_pack);
 
		return false;
 
	}
 

	
 
#if defined(TTD_BIG_ENDIAN)
 
	for (i = 0; i != 32; i++) {
 
		lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]);
 
		lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
 
	}
 
#endif
 

	
 
	tot_count = 0;
 
	for (i = 0; i != 32; i++) {
 
		uint num = lang_pack->offsets[i];
0 comments (0 inline, 0 general)