Fix some type-size safety issues.

Expecting int to be 32 bits is a little dangerous, and the function
versions of swap/noswap should be unsigned rather than signed.
This commit is contained in:
Bill Currie 2012-08-19 13:37:06 +09:00
parent 358ea4ef9a
commit 9bfcdad35a
3 changed files with 20 additions and 20 deletions

View file

@ -75,10 +75,10 @@
extern qboolean bigendien;
short _ShortSwap (short l);
short _ShortNoSwap (short l);
int _LongSwap (int l);
int _LongNoSwap (int l);
uint16_t _ShortSwap (uint16_t l);
uint16_t _ShortNoSwap (uint16_t l);
uint32_t _LongSwap (uint32_t l);
uint32_t _LongNoSwap (uint32_t l);
float _FloatSwap (float f);
float _FloatNoSwap (float f);

View file

@ -47,8 +47,8 @@ VISIBLE qboolean bigendien = true;;
#endif
VISIBLE short
_ShortSwap (short l)
VISIBLE uint16_t
_ShortSwap (uint16_t l)
{
byte b1, b2;
@ -58,14 +58,14 @@ _ShortSwap (short l)
return (b1 << 8) + b2;
}
VISIBLE short
_ShortNoSwap (short l)
VISIBLE uint16_t
_ShortNoSwap (uint16_t l)
{
return l;
}
VISIBLE int
_LongSwap (int l)
VISIBLE uint32_t
_LongSwap (uint32_t l)
{
byte b1, b2, b3, b4;
@ -77,8 +77,8 @@ _LongSwap (int l)
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
}
VISIBLE int
_LongNoSwap (int l)
VISIBLE uint32_t
_LongNoSwap (uint32_t l)
{
return l;
}

View file

@ -349,15 +349,15 @@ LoadLBM (char *filename, byte **picture, byte **palette)
// parse the LBM header
LBM_P = LBMbuffer;
if (*(int *) LBMbuffer != LittleLong (FORMID))
if (*(uint32_t *) LBMbuffer != LittleLong (FORMID))
Sys_Error ("No FORM ID at start of file!\n");
LBM_P += 4;
formlength = BigLong (*(int *) LBM_P );
formlength = BigLong (*(uint32_t *) LBM_P );
LBM_P += 4;
LBMEND_P = LBM_P + Align (formlength);
formtype = LittleLong (*(int *) LBM_P);
formtype = LittleLong (*(uint32_t *) LBM_P);
if (formtype != ILBMID && formtype != PBMID)
Sys_Error ("Unrecognized form type: %c%c%c%c\n", formtype & 0xff,
@ -467,7 +467,7 @@ void
WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
{
byte *lbm, *lbmptr;
int *formlength, *bmhdlength, *cmaplength, *bodylength;
uint32_t *formlength, *bmhdlength, *cmaplength, *bodylength;
int length;
bmhd_t basebmhd;
@ -479,7 +479,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
*lbmptr++ = 'R';
*lbmptr++ = 'M';
formlength = (int*)lbmptr;
formlength = (uint32_t*)lbmptr;
lbmptr+=4; // leave space for length
*lbmptr++ = 'P';
@ -493,7 +493,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
*lbmptr++ = 'H';
*lbmptr++ = 'D';
bmhdlength = (int *) lbmptr;
bmhdlength = (uint32_t *) lbmptr;
lbmptr += 4; // leave space for length
memset (&basebmhd, 0, sizeof (basebmhd));
@ -519,7 +519,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
*lbmptr++ = 'A';
*lbmptr++ = 'P';
cmaplength = (int *) lbmptr;
cmaplength = (uint32_t *) lbmptr;
lbmptr += 4; // leave space for length
memcpy (lbmptr, palette, 768);
@ -536,7 +536,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
*lbmptr++ = 'D';
*lbmptr++ = 'Y';
bodylength = (int *) lbmptr;
bodylength = (uint32_t *) lbmptr;
lbmptr += 4; // leave space for length
memcpy (lbmptr, data, width * height);