mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 13:10:34 +00:00
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:
parent
358ea4ef9a
commit
9bfcdad35a
3 changed files with 20 additions and 20 deletions
|
@ -75,10 +75,10 @@
|
||||||
|
|
||||||
extern qboolean bigendien;
|
extern qboolean bigendien;
|
||||||
|
|
||||||
short _ShortSwap (short l);
|
uint16_t _ShortSwap (uint16_t l);
|
||||||
short _ShortNoSwap (short l);
|
uint16_t _ShortNoSwap (uint16_t l);
|
||||||
int _LongSwap (int l);
|
uint32_t _LongSwap (uint32_t l);
|
||||||
int _LongNoSwap (int l);
|
uint32_t _LongNoSwap (uint32_t l);
|
||||||
float _FloatSwap (float f);
|
float _FloatSwap (float f);
|
||||||
float _FloatNoSwap (float f);
|
float _FloatNoSwap (float f);
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ VISIBLE qboolean bigendien = true;;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
VISIBLE short
|
VISIBLE uint16_t
|
||||||
_ShortSwap (short l)
|
_ShortSwap (uint16_t l)
|
||||||
{
|
{
|
||||||
byte b1, b2;
|
byte b1, b2;
|
||||||
|
|
||||||
|
@ -58,14 +58,14 @@ _ShortSwap (short l)
|
||||||
return (b1 << 8) + b2;
|
return (b1 << 8) + b2;
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE short
|
VISIBLE uint16_t
|
||||||
_ShortNoSwap (short l)
|
_ShortNoSwap (uint16_t l)
|
||||||
{
|
{
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE int
|
VISIBLE uint32_t
|
||||||
_LongSwap (int l)
|
_LongSwap (uint32_t l)
|
||||||
{
|
{
|
||||||
byte b1, b2, b3, b4;
|
byte b1, b2, b3, b4;
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ _LongSwap (int l)
|
||||||
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
|
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE int
|
VISIBLE uint32_t
|
||||||
_LongNoSwap (int l)
|
_LongNoSwap (uint32_t l)
|
||||||
{
|
{
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,15 +349,15 @@ LoadLBM (char *filename, byte **picture, byte **palette)
|
||||||
|
|
||||||
// parse the LBM header
|
// parse the LBM header
|
||||||
LBM_P = LBMbuffer;
|
LBM_P = LBMbuffer;
|
||||||
if (*(int *) LBMbuffer != LittleLong (FORMID))
|
if (*(uint32_t *) LBMbuffer != LittleLong (FORMID))
|
||||||
Sys_Error ("No FORM ID at start of file!\n");
|
Sys_Error ("No FORM ID at start of file!\n");
|
||||||
|
|
||||||
LBM_P += 4;
|
LBM_P += 4;
|
||||||
formlength = BigLong (*(int *) LBM_P );
|
formlength = BigLong (*(uint32_t *) LBM_P );
|
||||||
LBM_P += 4;
|
LBM_P += 4;
|
||||||
LBMEND_P = LBM_P + Align (formlength);
|
LBMEND_P = LBM_P + Align (formlength);
|
||||||
|
|
||||||
formtype = LittleLong (*(int *) LBM_P);
|
formtype = LittleLong (*(uint32_t *) LBM_P);
|
||||||
|
|
||||||
if (formtype != ILBMID && formtype != PBMID)
|
if (formtype != ILBMID && formtype != PBMID)
|
||||||
Sys_Error ("Unrecognized form type: %c%c%c%c\n", formtype & 0xff,
|
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)
|
WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
|
||||||
{
|
{
|
||||||
byte *lbm, *lbmptr;
|
byte *lbm, *lbmptr;
|
||||||
int *formlength, *bmhdlength, *cmaplength, *bodylength;
|
uint32_t *formlength, *bmhdlength, *cmaplength, *bodylength;
|
||||||
int length;
|
int length;
|
||||||
bmhd_t basebmhd;
|
bmhd_t basebmhd;
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
|
||||||
*lbmptr++ = 'R';
|
*lbmptr++ = 'R';
|
||||||
*lbmptr++ = 'M';
|
*lbmptr++ = 'M';
|
||||||
|
|
||||||
formlength = (int*)lbmptr;
|
formlength = (uint32_t*)lbmptr;
|
||||||
lbmptr+=4; // leave space for length
|
lbmptr+=4; // leave space for length
|
||||||
|
|
||||||
*lbmptr++ = 'P';
|
*lbmptr++ = 'P';
|
||||||
|
@ -493,7 +493,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
|
||||||
*lbmptr++ = 'H';
|
*lbmptr++ = 'H';
|
||||||
*lbmptr++ = 'D';
|
*lbmptr++ = 'D';
|
||||||
|
|
||||||
bmhdlength = (int *) lbmptr;
|
bmhdlength = (uint32_t *) lbmptr;
|
||||||
lbmptr += 4; // leave space for length
|
lbmptr += 4; // leave space for length
|
||||||
|
|
||||||
memset (&basebmhd, 0, sizeof (basebmhd));
|
memset (&basebmhd, 0, sizeof (basebmhd));
|
||||||
|
@ -519,7 +519,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
|
||||||
*lbmptr++ = 'A';
|
*lbmptr++ = 'A';
|
||||||
*lbmptr++ = 'P';
|
*lbmptr++ = 'P';
|
||||||
|
|
||||||
cmaplength = (int *) lbmptr;
|
cmaplength = (uint32_t *) lbmptr;
|
||||||
lbmptr += 4; // leave space for length
|
lbmptr += 4; // leave space for length
|
||||||
|
|
||||||
memcpy (lbmptr, palette, 768);
|
memcpy (lbmptr, palette, 768);
|
||||||
|
@ -536,7 +536,7 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
|
||||||
*lbmptr++ = 'D';
|
*lbmptr++ = 'D';
|
||||||
*lbmptr++ = 'Y';
|
*lbmptr++ = 'Y';
|
||||||
|
|
||||||
bodylength = (int *) lbmptr;
|
bodylength = (uint32_t *) lbmptr;
|
||||||
lbmptr += 4; // leave space for length
|
lbmptr += 4; // leave space for length
|
||||||
|
|
||||||
memcpy (lbmptr, data, width * height);
|
memcpy (lbmptr, data, width * height);
|
||||||
|
|
Loading…
Reference in a new issue