mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-27 06:13:01 +00:00
Fix alignment issues in message sending/reading that would crash IRIX, thanks to Canavan for supplying a shell where I could fix this (#5077)
This commit is contained in:
parent
4c5e9963e3
commit
242c938d7f
3 changed files with 51 additions and 18 deletions
|
@ -140,23 +140,28 @@ void MSG_WriteBits( msg_t *msg, int value, int bits ) {
|
|||
bits = -bits;
|
||||
}
|
||||
if (msg->oob) {
|
||||
if (bits==8) {
|
||||
if(bits==8)
|
||||
{
|
||||
msg->data[msg->cursize] = value;
|
||||
msg->cursize += 1;
|
||||
msg->bit += 8;
|
||||
} else if (bits==16) {
|
||||
unsigned short *sp = (unsigned short *)&msg->data[msg->cursize];
|
||||
*sp = LittleShort(value);
|
||||
}
|
||||
else if(bits==16)
|
||||
{
|
||||
short temp = value;
|
||||
|
||||
CopyLittleShort(&msg->data[msg->cursize], &temp);
|
||||
msg->cursize += 2;
|
||||
msg->bit += 16;
|
||||
} else if (bits==32) {
|
||||
unsigned int *ip = (unsigned int *)&msg->data[msg->cursize];
|
||||
*ip = LittleLong(value);
|
||||
}
|
||||
else if(bits==32)
|
||||
{
|
||||
CopyLittleLong(&msg->data[msg->cursize], &value);
|
||||
msg->cursize += 4;
|
||||
msg->bit += 32;
|
||||
} else {
|
||||
Com_Error(ERR_DROP, "can't read %d bits", bits);
|
||||
}
|
||||
else
|
||||
Com_Error(ERR_DROP, "can't write %d bits", bits);
|
||||
} else {
|
||||
// fp = fopen("c:\\netchan.bin", "a");
|
||||
value &= (0xffffffff>>(32-bits));
|
||||
|
@ -198,23 +203,29 @@ int MSG_ReadBits( msg_t *msg, int bits ) {
|
|||
}
|
||||
|
||||
if (msg->oob) {
|
||||
if (bits==8) {
|
||||
if(bits==8)
|
||||
{
|
||||
value = msg->data[msg->readcount];
|
||||
msg->readcount += 1;
|
||||
msg->bit += 8;
|
||||
} else if (bits==16) {
|
||||
unsigned short *sp = (unsigned short *)&msg->data[msg->readcount];
|
||||
value = LittleShort(*sp);
|
||||
}
|
||||
else if(bits==16)
|
||||
{
|
||||
short temp;
|
||||
|
||||
CopyLittleShort(&temp, &msg->data[msg->readcount]);
|
||||
value = temp;
|
||||
msg->readcount += 2;
|
||||
msg->bit += 16;
|
||||
} else if (bits==32) {
|
||||
unsigned int *ip = (unsigned int *)&msg->data[msg->readcount];
|
||||
value = LittleLong(*ip);
|
||||
}
|
||||
else if(bits==32)
|
||||
{
|
||||
CopyLittleLong(&value, &msg->data[msg->readcount]);
|
||||
msg->readcount += 4;
|
||||
msg->bit += 32;
|
||||
} else {
|
||||
Com_Error(ERR_DROP, "can't read %d bits", bits);
|
||||
}
|
||||
else
|
||||
Com_Error(ERR_DROP, "can't read %d bits", bits);
|
||||
} else {
|
||||
nbits = 0;
|
||||
if (bits&7) {
|
||||
|
|
|
@ -348,6 +348,8 @@ float FloatSwap (const float *f);
|
|||
#error "Endianness defined as both big and little"
|
||||
#elif defined( Q3_BIG_ENDIAN )
|
||||
|
||||
#define CopyLittleShort(dest, src) CopyShortSwap(dest, src)
|
||||
#define CopyLittleLong(dest, src) CopyLongSwap(dest, src)
|
||||
#define LittleShort(x) ShortSwap(x)
|
||||
#define LittleLong(x) LongSwap(x)
|
||||
#define LittleFloat(x) FloatSwap(&x)
|
||||
|
@ -357,6 +359,8 @@ float FloatSwap (const float *f);
|
|||
|
||||
#elif defined( Q3_LITTLE_ENDIAN )
|
||||
|
||||
#define CopyLittleShort(dest, src) Com_Memcpy(dest, src, 2)
|
||||
#define CopyLittleLong(dest, src) Com_Memcpy(dest, src, 4)
|
||||
#define LittleShort
|
||||
#define LittleLong
|
||||
#define LittleFloat
|
||||
|
|
|
@ -129,6 +129,24 @@ float BigFloat (const float *l) {return _BigFloat(l);}
|
|||
float LittleFloat (const float *l) {return _LittleFloat(l);}
|
||||
*/
|
||||
|
||||
void CopyShortSwap(void *dest, void *src)
|
||||
{
|
||||
byte *to = dest, *from = src;
|
||||
|
||||
to[0] = from[1];
|
||||
to[1] = from[0];
|
||||
}
|
||||
|
||||
void CopyLongSwap(void *dest, void *src)
|
||||
{
|
||||
byte *to = dest, *from = src;
|
||||
|
||||
to[0] = from[3];
|
||||
to[1] = from[2];
|
||||
to[2] = from[1];
|
||||
to[3] = from[0];
|
||||
}
|
||||
|
||||
short ShortSwap (short l)
|
||||
{
|
||||
byte b1,b2;
|
||||
|
|
Loading…
Reference in a new issue