diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/net_sock.h | 4 | ||||
-rw-r--r-- | source/protocol.h | 6 | ||||
-rw-r--r-- | source/q_msg.c | 6 | ||||
-rw-r--r-- | source/q_msg.h | 14 | ||||
-rw-r--r-- | source/q_shared.h | 33 | ||||
-rw-r--r-- | source/r_images.c | 6 | ||||
-rw-r--r-- | source/r_shared.h | 14 | ||||
-rw-r--r-- | source/snd_mem.c | 38 |
8 files changed, 63 insertions, 58 deletions
diff --git a/source/net_sock.h b/source/net_sock.h index fb8a970..2669e09 100644 --- a/source/net_sock.h +++ b/source/net_sock.h @@ -116,8 +116,8 @@ static inline qboolean NET_IsLanAddress( const netadr_t *adr ) { if( adr->ip[0] == 127 || adr->ip[0] == 10 ) { return qtrue; } - if( *( uint16_t * )adr->ip == MakeShort( 192, 168 ) || - *( uint16_t * )adr->ip == MakeShort( 172, 16 ) ) + if( *( uint16_t * )adr->ip == MakeRawShort( 192, 168 ) || + *( uint16_t * )adr->ip == MakeRawShort( 172, 16 ) ) { return qtrue; } diff --git a/source/protocol.h b/source/protocol.h index 95dc198..deb273f 100644 --- a/source/protocol.h +++ b/source/protocol.h @@ -86,10 +86,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_PACKET_STRINGCMDS 8 #define MAX_PACKET_USERINFOS 8 -#define CS_BITMAP_BYTES (MAX_CONFIGSTRINGS/8) // 260 -#define CS_BITMAP_LONGS (CS_BITMAP_BYTES/4 ) +#define CS_BITMAP_BYTES (MAX_CONFIGSTRINGS/8) // 260 +#define CS_BITMAP_LONGS (CS_BITMAP_BYTES/4 ) -#define MVD_MAGIC MakeLong('M','V','D','2') +#define MVD_MAGIC MakeRawLong('M','V','D','2') // // server to client diff --git a/source/q_msg.c b/source/q_msg.c index bbfd655..5887a88 100644 --- a/source/q_msg.c +++ b/source/q_msg.c @@ -1488,7 +1488,7 @@ int MSG_ReadShort( void ) { if (!buf) { c = -1; } else { - c = (signed short)(buf[0] | (buf[1]<<8)); + c = (signed short)LittleShortMem(buf); } return c; @@ -1501,7 +1501,7 @@ int MSG_ReadWord( void ) { if (!buf) { c = -1; } else { - c = (unsigned short)(buf[0] | (buf[1]<<8)); + c = (unsigned short)LittleShortMem(buf); } return c; @@ -1514,7 +1514,7 @@ int MSG_ReadLong( void ) { if (!buf) { c = -1; } else { - c = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24); + c = LittleLongMem(buf); } return c; diff --git a/source/q_msg.h b/source/q_msg.h index 9aea1ce..cae1f57 100644 --- a/source/q_msg.h +++ b/source/q_msg.h @@ -22,13 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // q_msg.h // -#define SZ_MSG_WRITE MakeLong( 'w', 'r', 'i', 't' ) -#define SZ_MSG_READ MakeLong( 'r', 'e', 'a', 'd' ) -#define SZ_NC_SEND_OLD MakeLong( 'n', 'c', '1', 's' ) -#define SZ_NC_SEND_NEW MakeLong( 'n', 'c', '2', 's' ) -#define SZ_NC_SEND_FRG MakeLong( 'n', 'c', '2', 'f' ) -#define SZ_NC_FRG_IN MakeLong( 'n', 'c', '2', 'i' ) -#define SZ_NC_FRG_OUT MakeLong( 'n', 'c', '2', 'o' ) +#define SZ_MSG_WRITE MakeRawLong( 'w', 'r', 'i', 't' ) +#define SZ_MSG_READ MakeRawLong( 'r', 'e', 'a', 'd' ) +#define SZ_NC_SEND_OLD MakeRawLong( 'n', 'c', '1', 's' ) +#define SZ_NC_SEND_NEW MakeRawLong( 'n', 'c', '2', 's' ) +#define SZ_NC_SEND_FRG MakeRawLong( 'n', 'c', '2', 'f' ) +#define SZ_NC_FRG_IN MakeRawLong( 'n', 'c', '2', 'i' ) +#define SZ_NC_FRG_OUT MakeRawLong( 'n', 'c', '2', 'o' ) typedef struct sizebuf_s { uint32_t tag; diff --git a/source/q_shared.h b/source/q_shared.h index 0cdb97c..541b046 100644 --- a/source/q_shared.h +++ b/source/q_shared.h @@ -474,23 +474,14 @@ char *va( const char *format, ... ) q_printf( 1, 2 ); //============================================= static inline uint16_t ShortSwap( uint16_t s ) { - byte b1, b2; - - b1 = s & 255; - b2 = ( s >> 8 ) & 255; - - return ( b1 << 8 ) | b2; + s = ( s >> 8 ) | ( s << 8 ); + return s; } static inline uint32_t LongSwap( uint32_t l ) { - byte b1, b2, b3, b4; - - b1 = l & 255; - b2 = ( l >> 8 ) & 255; - b3 = ( l >> 16 ) & 255; - b4 = ( l >> 24 ) & 255; - - return ( b1 << 24 ) | ( b2 << 16 ) | ( b3 << 8 ) | b4; + l = ( ( l >> 8 ) & 0x00ff00ff ) | ( ( l << 8 ) & 0xff00ff00 ); + l = ( l >> 16 ) | ( l << 16 ); + return l; } static inline float FloatSwap( float f ) { @@ -511,8 +502,8 @@ static inline float FloatSwap( float f ) { #define LittleShort(x) ((uint16_t)(x)) #define LittleLong(x) ((uint32_t)(x)) #define LittleFloat(x) ((float)(x)) -#define MakeLong(b1,b2,b3,b4) (((b4)<<24)|((b3)<<16)|((b2)<<8)|(b1)) -#define MakeShort(b1,b2) (((b2)<<8)|(b1)) +#define MakeRawLong(b1,b2,b3,b4) (((b4)<<24)|((b3)<<16)|((b2)<<8)|(b1)) +#define MakeRawShort(b1,b2) (((b2)<<8)|(b1)) #elif __BYTE_ORDER == __BIG_ENDIAN #define BigShort(x) ((uint16_t)(x)) #define BigLong(x) ((uint32_t)(x)) @@ -520,12 +511,18 @@ static inline float FloatSwap( float f ) { #define LittleShort ShortSwap #define LittleLong LongSwap #define LittleFloat FloatSwap -#define MakeLong(b1,b2,b3,b4) (((b1)<<24)|((b2)<<16)|((b3)<<8)|(b4)) -#define MakeShort(b1,b2) (((b1)<<8)|(b2)) +#define MakeRawLong(b1,b2,b3,b4) (((b1)<<24)|((b2)<<16)|((b3)<<8)|(b4)) +#define MakeRawShort(b1,b2) (((b1)<<8)|(b2)) #else #error Unknown byte order #endif +#define LittleLongMem(p) (((p)[3]<<24)|((p)[2]<<16)|((p)[1]<<8)|(p)[0]) +#define LittleShortMem(p) (((p)[1]<<8)|(p)[0]) + +#define RawLongMem(p) MakeRawLong((p)[0],(p)[1],(p)[2],(p)[3]) +#define RawShortMem(p) MakeRawShort((p)[0],(p)[1]) + #define LittleVector(a,b) \ ((b)[0]=LittleFloat((a)[0]),\ (b)[1]=LittleFloat((a)[1]),\ diff --git a/source/r_images.c b/source/r_images.c index e082629..8468c61 100644 --- a/source/r_images.c +++ b/source/r_images.c @@ -472,8 +472,8 @@ void IMG_LoadTGA( const char *filename, byte **pic, int *width, int *height ) { id_length = buffer[0]; image_type = buffer[2]; - w = MakeShort( buffer[12], buffer[13] ); - h = MakeShort( buffer[14], buffer[15] ); + w = LittleShortMem( &buffer[12] ); + h = LittleShortMem( &buffer[14] ); pixel_size = buffer[16]; attributes = buffer[17]; @@ -1310,7 +1310,7 @@ image_t *IMG_Find( const char *name, imagetype_t type ) { ext = buffer + length; Q_strlwr( ext + 1 ); - extHash = MakeLong( '.', ext[1], ext[2], ext[3] ); + extHash = MakeRawLong( '.', ext[1], ext[2], ext[3] ); // // create the pic from disk diff --git a/source/r_shared.h b/source/r_shared.h index 507bfd6..ae0fea5 100644 --- a/source/r_shared.h +++ b/source/r_shared.h @@ -27,9 +27,9 @@ IMAGE MANAGER */ #if USE_BGRA -#define MakeColor( r, g, b, a ) MakeLong( b, g, r, a ) +#define MakeColor( r, g, b, a ) MakeRawLong( b, g, r, a ) #else -#define MakeColor( r, g, b, a ) MakeLong( r, g, b, a ) +#define MakeColor( r, g, b, a ) MakeRawLong( r, g, b, a ) #endif #define R_Malloc( size ) Z_TagMalloc( size, TAG_RENDERER ) @@ -83,11 +83,11 @@ typedef enum { it_tmp } imagetype_t; -#define EXTENSION_PNG MakeLong( '.', 'p', 'n', 'g' ) -#define EXTENSION_TGA MakeLong( '.', 't', 'g', 'a' ) -#define EXTENSION_JPG MakeLong( '.', 'j', 'p', 'g' ) -#define EXTENSION_PCX MakeLong( '.', 'p', 'c', 'x' ) -#define EXTENSION_WAL MakeLong( '.', 'w', 'a', 'l' ) +#define EXTENSION_PNG MakeRawLong( '.', 'p', 'n', 'g' ) +#define EXTENSION_TGA MakeRawLong( '.', 't', 'g', 'a' ) +#define EXTENSION_JPG MakeRawLong( '.', 'j', 'p', 'g' ) +#define EXTENSION_PCX MakeRawLong( '.', 'p', 'c', 'x' ) +#define EXTENSION_WAL MakeRawLong( '.', 'w', 'a', 'l' ) typedef struct image_s { list_t entry; diff --git a/source/snd_mem.c b/source/snd_mem.c index 287cfea..c347726 100644 --- a/source/snd_mem.c +++ b/source/snd_mem.c @@ -110,8 +110,7 @@ static int GetLittleShort( void ) { return -1; } - val = data_p[0]; - val |= data_p[1] << 8; + val = LittleShortMem( data_p ); data_p += 2; return val; } @@ -123,10 +122,19 @@ static int GetLittleLong( void ) { return -1; } - val = data_p[0]; - val |= data_p[1] << 8; - val |= data_p[2] << 16; - val |= data_p[3] << 24; + val = LittleLongMem( data_p ); + data_p += 4; + return val; +} + +static int GetRawLong( void ) { + int val; + + if( data_p + 4 > iff_end ) { + return -1; + } + + val = RawLongMem( data_p ); data_p += 4; return val; } @@ -141,11 +149,11 @@ static void FindNextChunk( uint32_t search ) { return; // didn't find the chunk } - chunk = GetLittleLong(); + chunk = GetRawLong(); iff_chunk_len = GetLittleLong(); if( iff_chunk_len > iff_end - data_p ) { Com_DPrintf( "%s: oversize chunk %#x in %s\n", - __func__, chunk, s_info.name ); + __func__, LittleLong( chunk ), s_info.name ); data_p = NULL; return; } @@ -165,13 +173,13 @@ static void FindChunk( uint32_t search ) { FindNextChunk( search ); } -#define TAG_RIFF MakeLong( 'R', 'I', 'F', 'F' ) -#define TAG_WAVE MakeLong( 'W', 'A', 'V', 'E' ) -#define TAG_fmt MakeLong( 'f', 'm', 't', ' ' ) -#define TAG_cue MakeLong( 'c', 'u', 'e', ' ' ) -#define TAG_LIST MakeLong( 'L', 'I', 'S', 'T' ) -#define TAG_MARK MakeLong( 'M', 'A', 'R', 'K' ) -#define TAG_data MakeLong( 'd', 'a', 't', 'a' ) +#define TAG_RIFF MakeRawLong( 'R', 'I', 'F', 'F' ) +#define TAG_WAVE MakeRawLong( 'W', 'A', 'V', 'E' ) +#define TAG_fmt MakeRawLong( 'f', 'm', 't', ' ' ) +#define TAG_cue MakeRawLong( 'c', 'u', 'e', ' ' ) +#define TAG_LIST MakeRawLong( 'L', 'I', 'S', 'T' ) +#define TAG_MARK MakeRawLong( 'M', 'A', 'R', 'K' ) +#define TAG_data MakeRawLong( 'd', 'a', 't', 'a' ) /* ============ |