ref: 7684067e918611c35904583b6d3535ca3b6273b9
parent: 6ec1defca988454ab5f0d4f98ea0a12c9e39a5f3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 14 15:20:32 EDT 2024
reduce UB complaints
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -443,7 +443,7 @@
*/
static void CL_ParseClientdata (unsigned int bits)
{
- int i, j, weaponmodel;
+ unsigned i, j, weaponmodel;
if(bits & SU_MOREBITS){
bits |= MSG_ReadByte() << 16;
@@ -455,8 +455,7 @@
cl.idealpitch = (bits & SU_IDEALPITCH) ? MSG_ReadChar() : 0;
VectorCopy(cl.mvelocity[0], cl.mvelocity[1]);
- for (i=0 ; i<3 ; i++)
- {
+ for(i = 0; i < 3; i++){
cl.punchangle[i] = (bits & (SU_PUNCH1<<i)) ? MSG_ReadChar() : 0;
cl.mvelocity[0][i] = (bits & (SU_VELOCITY1<<i)) ? MSG_ReadChar()*16 : 0;
}
@@ -463,8 +462,8 @@
i = (bits & SU_ITEMS) ? MSG_ReadLong() : cl.items;
if(cl.items != i){ // set flash times
- for (j=0 ; j<32 ; j++)
- if ( (i & (1<<j)) && !(cl.items & (1<<j)))
+ for(j = 0; j < 32; j++)
+ if((i & (1U<<j)) && !(cl.items & (1U<<j)))
cl.item_gettime[j] = cl.time;
cl.items = i;
}
@@ -477,7 +476,7 @@
cl.stats[STAT_HEALTH] = MSG_ReadShort();
cl.stats[STAT_AMMO] = MSG_ReadByte();
- for (i=0 ; i<4 ; i++)
+ for(i = 0; i < 4; i++)
cl.stats[STAT_SHELLS+i] = MSG_ReadByte();
i = MSG_ReadByte();
--- a/client.h
+++ b/client.h
@@ -128,7 +128,7 @@
// information for local display
int stats[MAX_CL_STATS]; // health, etc
- int items; // inventory bit flags
+ unsigned items; // inventory bit flags
float item_gettime[32]; // cl.time of aquiring item, for blinking
float faceanimtime; // use anim frame if cl.time < this
--- a/cmprocess.c
+++ b/cmprocess.c
@@ -4,7 +4,7 @@
void
cmprocess(s16int cm[4*4], void *in_, void *out_, int n)
{
- u32int *in, *out;
+ pixel_t *in, *out;
int i;
in = in_;
@@ -28,6 +28,6 @@
clamp(y[2], 0, 255),
0xff,
};
- *out++ = z[0]<<0 | z[1]<<8 | z[2]<<16 | z[3]<<24;
+ *out++ = z[0]<<0 | z[1]<<8 | z[2]<<16 | (pixel_t)z[3]<<24;
}
}
--- a/common.c
+++ b/common.c
@@ -280,9 +280,9 @@
}
c = net_message.data[msg_readcount]
- + (net_message.data[msg_readcount+1]<<8)
- + (net_message.data[msg_readcount+2]<<16)
- + (net_message.data[msg_readcount+3]<<24);
+ | (net_message.data[msg_readcount+1]<<8)
+ | (net_message.data[msg_readcount+2]<<16)
+ | (net_message.data[msg_readcount+3]<<24);
msg_readcount += 4;
--- a/common.h
+++ b/common.h
@@ -64,7 +64,7 @@
float f32le(u32int u);
-#define le32(p) (p += 4, (int)(p[-4]|p[-3]<<8|p[-2]<<16|p[-1]<<24))
+#define le32(p) (p += 4, (int)(p[-4]|p[-3]<<8|p[-2]<<16|(u32int)p[-1]<<24))
#define le32u(p) (u32int)le32(p)
#define le16(p) (p += 2, (short)(p[-2]|p[-1]<<8))
#define le16u(p) (u16int)le16(p)
--- a/fs.c
+++ b/fs.c
@@ -213,7 +213,7 @@
u32int v;
v = get16(bf);
- return v | get16(bf) << 16;
+ return v | (u32int)get16(bf) << 16;
}
static float
--- a/model_bsp.c
+++ b/model_bsp.c
@@ -303,7 +303,7 @@
for(i = 0; i < mod->numleafs; i++, out++){
out->contents = le32(in);
- out->compressed_vis = (p = le32(in)) < 0 ? nil : mod->visdata + p;
+ out->compressed_vis = ((p = le32(in)) < 0 || mod->visdata == nil) ? nil : mod->visdata + p;
for(j = 0; j < 3; j++)
out->minmaxs[0+j] = le16(in);
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -72,7 +72,7 @@
{
int i;
- if(s == nil)
+ if(s == nil || pr->strings == nil)
return 0;
if(s >= pr->strings && s < pr->strings+pr->strings_size-1)
return s - pr->strings;
--- a/softfloat.c
+++ b/softfloat.c
@@ -637,7 +637,7 @@
shiftDist = softfloat_countLeadingZeros64( sig );
z.exp = -shiftDist;
- z.sig = sig<<shiftDist;
+ z.sig = shiftDist < 64 ? (sig<<shiftDist) : 0;
return z;
}
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -114,11 +114,11 @@
void
setpal(byte *p0)
{
- int x;
+ pixel_t x;
byte *p;
for(p = p0, x = 0; x < 256; x++, p += 3){
- q1pal[x] = (x < 256-32 ? 0xff : 0)<<24 | p[0]<<16 | p[1]<<8 | p[2];
+ q1pal[x] = (x < 256U-32U ? 0xffU : 0)<<24 | p[0]<<16 | p[1]<<8 | p[2];
q1palindexed[x] = opaque(q1pal[x]) ? (x<<24 | p[0]<<16 | p[1]<<8 | p[2]) : 0;
}
q1pal[255] = 0;