common code: clean up code by cppcheck recomendations

This commit is contained in:
Denis Pauk 2024-02-05 23:21:50 +02:00
parent 10cc304778
commit 3039fe723d
11 changed files with 133 additions and 140 deletions

View file

@ -288,6 +288,24 @@ Mod_LoadFrames_DKM2(dmdx_t *pheader, const byte *src, size_t inframesize, vec3_t
}
}
static void
Mod_LoadFixImages(const char* mod_name, dmdx_t *pheader, qboolean internal)
{
int i;
for (i = 0; i < pheader->num_skins; i++)
{
char *skin;
skin = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME;
skin[MAX_SKINNAME - 1] = 0;
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load %s '%s'\n",
__func__, mod_name, i, internal ? "internal": "external", skin);
}
}
/*
=================
Mod_LoadModel_MDL
@ -590,16 +608,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
}
}
{
int i;
for (i = 0; i < pheader->num_skins; i++)
{
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load internal '%s'\n",
__func__, mod_name, i,
(char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME);
}
}
Mod_LoadFixImages(mod_name, pheader, true);
*type = mod_alias;
@ -833,17 +842,7 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
}
free(vertx);
/* TODO: make separate function */
for (i = 0; i < pheader->num_skins; i++)
{
char *skinname;
skinname = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME;
skinname[MAX_SKINNAME - 1] = 0;
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n",
__func__, mod_name, i, skinname);
}
Mod_LoadFixImages(mod_name, pheader, false);
*type = mod_alias;
@ -1017,16 +1016,7 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
memcpy((char *)pheader + pheader->ofs_skins, (char *)buffer + pinmodel.ofs_skins,
pheader->num_skins * MAX_SKINNAME);
for (i = 0; i < pheader->num_skins; i++)
{
char *skin;
skin = (char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME;
skin[MAX_SKINNAME - 1] = 0;
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n",
__func__, mod_name, i, skin);
}
Mod_LoadFixImages(mod_name, pheader, false);
*type = mod_alias;
@ -1357,16 +1347,7 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
src += size;
}
{
int i;
for (i = 0; i < pheader->num_skins; i++)
{
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n",
__func__, mod_name, i,
(char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME);
}
}
Mod_LoadFixImages(mod_name, pheader, false);
*type = mod_alias;
@ -1492,12 +1473,7 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
Mod_LoadDkmTriangleList(pheader,
(dkmtriangle_t *)((byte *)buffer + header.ofs_tris));
for (i = 0; i < pheader->num_skins; i++)
{
R_Printf(PRINT_DEVELOPER, "%s: %s #%d: Should load external '%s'\n",
__func__, mod_name, i,
(char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME);
}
Mod_LoadFixImages(mod_name, pheader, false);
*type = mod_alias;

View file

@ -289,7 +289,7 @@ LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *heigh
void
GetPCXInfo(const char *origname, int *width, int *height)
{
pcx_t *pcx;
const pcx_t *pcx;
byte *raw;
char filename[256];
@ -383,7 +383,7 @@ GenerateColormap(const byte *palette, byte *out_colormap)
}
void
GetPCXPalette24to8(byte *d_8to24table, byte** d_16to8table)
GetPCXPalette24to8(const byte *d_8to24table, byte** d_16to8table)
{
unsigned char * table16to8;
char tablefile[] = "pics/16to8.dat";
@ -453,7 +453,6 @@ GetPCXPalette(byte **colormap, unsigned *d_8to24table)
{
char filename[] = "pics/colormap.pcx";
byte *pal;
int i;
/* get the palette and colormap */
LoadPCX(filename, colormap, &pal, NULL, NULL);
@ -502,11 +501,13 @@ GetPCXPalette(byte **colormap, unsigned *d_8to24table)
if (!*colormap || !pal)
{
int i;
R_Printf(PRINT_ALL, "%s: Couldn't load %s, use generated palette\n",
__func__, filename);
/* palette r:2bit, g:3bit, b:3bit */
for (i=0 ; i < 256; i++)
for (i = 0; i < 256; i++)
{
unsigned v;
@ -530,21 +531,25 @@ GetPCXPalette(byte **colormap, unsigned *d_8to24table)
GenerateColormap((const byte *)d_8to24table, *colormap);
return;
}
for (i = 0; i < 256; i++)
else
{
unsigned v;
int r, g, b;
int i;
r = pal[i*3+0];
g = pal[i*3+1];
b = pal[i*3+2];
for (i = 0; i < 256; i++)
{
unsigned v;
int r, g, b;
v = (255U<<24) + (r<<0) + (g<<8) + (b<<16);
d_8to24table[i] = LittleLong(v);
r = pal[i*3+0];
g = pal[i*3+1];
b = pal[i*3+2];
v = (255U<<24) + (r<<0) + (g<<8) + (b<<16);
d_8to24table[i] = LittleLong(v);
}
d_8to24table[255] &= LittleLong(0xffffff); // 255 is transparent
free(pal);
}
d_8to24table[255] &= LittleLong(0xffffff); // 255 is transparent
free (pal);
}

View file

@ -123,7 +123,7 @@ ResizeSTB(const byte *input_pixels, int input_width, int input_height,
void
SmoothColorImage(unsigned *dst, size_t size, size_t rstep)
{
unsigned *full_size;
const unsigned *full_size;
unsigned last_color;
unsigned *last_diff;
@ -253,7 +253,8 @@ scale2x(const byte *src, byte *dst, int width, int height)
{
const byte *in_buff = src;
byte *out_buff = dst;
byte *out_buff_full = dst + ((width * height) << 2);
const byte *out_buff_full = dst + ((width * height) << 2);
while (out_buff < out_buff_full)
{
int x;
@ -340,7 +341,8 @@ scale3x(const byte *src, byte *dst, int width, int height)
{
const byte *in_buff = src;
byte *out_buff = dst;
byte *out_buff_full = dst + ((width * height) * 9);
const byte *out_buff_full = dst + ((width * height) * 9);
while (out_buff < out_buff_full)
{
int x;

View file

@ -61,7 +61,7 @@ R_TextureAnimation(const entity_t *currententity, const mtexinfo_t *tex)
}
qboolean
R_AreaVisible(const byte *areabits, mleaf_t *pleaf)
R_AreaVisible(const byte *areabits, const mleaf_t *pleaf)
{
int area;
@ -85,7 +85,7 @@ R_AreaVisible(const byte *areabits, mleaf_t *pleaf)
* Returns true if the box is completely outside the frustom
*/
qboolean
R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum)
R_CullBox(vec3_t mins, vec3_t maxs, const cplane_t *frustum)
{
int i;
@ -101,7 +101,7 @@ R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum)
}
static int
R_SignbitsForPlane(cplane_t *out)
R_SignbitsForPlane(const cplane_t *out)
{
int bits, j;
@ -314,12 +314,13 @@ R_SubdividePolygon(int numverts, float *verts, msurface_t *warpface)
* can be done reasonably.
*/
void
R_SubdivideSurface(int *surfedges, mvertex_t *vertexes, medge_t *edges, msurface_t *fa)
R_SubdivideSurface(const int *surfedges, mvertex_t *vertexes, medge_t *edges,
msurface_t *fa)
{
const float *vec;
vec3_t verts[64];
int numverts;
int i;
float *vec;
/* convert edges back to a normal polygon */
numverts = 0;

View file

@ -31,7 +31,7 @@ LoadWalQ2(const char *origname, const char *name, const byte *data, size_t size,
imagetype_t type, loadimage_t load_image)
{
int width, height, ofs;
miptex_t *mt;
const miptex_t *mt;
mt = (miptex_t *)data;
@ -280,7 +280,7 @@ GetWalInfo(const char *origname, int *width, int *height)
if (size > sizeof(dkmtex_t) && *data == DKM_WAL_VERSION)
{
dkmtex_t *mt;
const dkmtex_t *mt;
mt = (dkmtex_t *)data;
@ -289,7 +289,7 @@ GetWalInfo(const char *origname, int *width, int *height)
}
else
{
miptex_t *mt;
const miptex_t *mt;
mt = (miptex_t *)data;

View file

@ -101,7 +101,7 @@ extern struct image_s* LoadM32(const char *origname, const char *namewe, imagety
loadimage_t load_image);
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
extern void GetPCXPalette(byte **colormap, unsigned *d_8to24table);
extern void GetPCXPalette24to8(byte *d_8to24table, byte** d_16to8table);
extern void GetPCXPalette24to8(const byte *d_8to24table, byte** d_16to8table);
extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height);
extern void GetPCXInfo(const char *origname, int *width, int *height);
extern void GetWalInfo(const char *name, int *width, int *height);
@ -370,11 +370,11 @@ extern void R_PushDlights(refdef_t *r_newrefdef, mnode_t *nodes, int r_dlightfra
msurface_t *surfaces);
extern struct image_s *R_TextureAnimation(const entity_t *currententity,
const mtexinfo_t *tex);
extern qboolean R_AreaVisible(const byte *areabits, mleaf_t *pleaf);
extern qboolean R_CullBox(vec3_t mins, vec3_t maxs, cplane_t *frustum);
extern qboolean R_AreaVisible(const byte *areabits, const mleaf_t *pleaf);
extern qboolean R_CullBox(vec3_t mins, vec3_t maxs, const cplane_t *frustum);
extern void R_SetFrustum(vec3_t vup, vec3_t vpn, vec3_t vright, vec3_t r_origin,
float fov_x, float fov_y, cplane_t *frustum);
extern void R_SubdivideSurface(int *surfedges, mvertex_t *vertexes, medge_t *edges,
extern void R_SubdivideSurface(const int *surfedges, mvertex_t *vertexes, medge_t *edges,
msurface_t *fa);
/* Mesh logic */

View file

@ -765,7 +765,7 @@ Cmd_RemoveCommand(const char *cmd_name)
}
qboolean
Cmd_Exists(char *cmd_name)
Cmd_Exists(const char *cmd_name)
{
cmd_function_t *cmd;

View file

@ -196,9 +196,7 @@ FloodArea_r(carea_t *area, int floodnum)
static void
FloodAreaConnections(void)
{
int i;
carea_t *area;
int floodnum;
int i, floodnum;
/* all current floods are now invalid */
floodvalid++;
@ -207,6 +205,8 @@ FloodAreaConnections(void)
/* area 0 is not used */
for (i = 1; i < cmod->numareas; i++)
{
carea_t *area;
area = &cmod->map_areas[i];
if (area->floodvalid == floodvalid)
@ -263,8 +263,6 @@ CM_AreasConnected(int area1, int area2)
int
CM_WriteAreaBits(byte *buffer, int area)
{
int i;
int floodnum;
int bytes;
bytes = (cmod->numareas + 7) >> 3;
@ -274,9 +272,10 @@ CM_WriteAreaBits(byte *buffer, int area)
/* for debugging, send everything */
memset(buffer, 255, bytes);
}
else
{
int floodnum, i;
memset(buffer, 0, bytes);
floodnum = cmod->map_areas[area].floodnum;
@ -320,12 +319,13 @@ CM_ReadPortalState(fileHandle_t f)
qboolean
CM_HeadnodeVisible(int nodenum, byte *visbits)
{
int leafnum1;
int cluster;
cnode_t *node;
const cnode_t *node;
if (nodenum < 0)
{
int leafnum1;
int cluster;
leafnum1 = -1 - nodenum;
cluster = cmod->map_leafs[leafnum1].cluster;
@ -359,11 +359,8 @@ CM_HeadnodeVisible(int nodenum, byte *visbits)
static void
CM_InitBoxHull(void)
{
int i;
int side;
cnode_t *c;
cplane_t *p;
cbrushside_t *s;
int i;
box_headnode = cmod->numnodes;
box_planes = &cmod->map_planes[cmod->numplanes];
@ -391,6 +388,10 @@ CM_InitBoxHull(void)
for (i = 0; i < 6; i++)
{
cbrushside_t *s;
cnode_t *c;
int side;
side = i & 1;
/* brush sides */
@ -514,12 +515,12 @@ static void
CM_BoxLeafnums_r(int nodenum, vec3_t leaf_mins, vec3_t leaf_maxs,
int *leaf_list, int *leaf_count, int leaf_maxcount)
{
cplane_t *plane;
cnode_t *node;
int s;
while (1)
{
const cplane_t *plane;
cnode_t *node;
int s;
if (nodenum < 0)
{
if ((*leaf_count) >= leaf_maxcount)
@ -544,12 +545,10 @@ CM_BoxLeafnums_r(int nodenum, vec3_t leaf_mins, vec3_t leaf_maxs,
{
nodenum = node->children[0];
}
else if (s == 2)
{
nodenum = node->children[1];
}
else
{
/* go down both */
@ -651,17 +650,18 @@ CM_TransformedPointContents(vec3_t p, int headnode,
static void
CM_ClipBoxToBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
vec3_t p2, trace_t *trace, cbrush_t *brush)
vec3_t p2, trace_t *trace, const cbrush_t *brush)
{
int i, j;
cplane_t *plane, *clipplane;
float dist;
float enterfrac, leavefrac;
vec3_t ofs;
float d1, d2;
qboolean getout, startout;
float f;
cbrushside_t *side, *leadside;
float enterfrac, leavefrac;
const cplane_t *clipplane;
qboolean getout, startout;
cplane_t *plane;
float d1, d2;
float dist;
vec3_t ofs;
int i, j;
float f;
enterfrac = -1;
leavefrac = 1;
@ -808,13 +808,11 @@ CM_ClipBoxToBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
static void
CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
trace_t *trace, cbrush_t *brush)
trace_t *trace, const cbrush_t *brush)
{
int i, j;
cplane_t *plane;
float dist;
vec3_t ofs;
float d1;
cbrushside_t *side;
if (!brush->numsides || !cmod->map_brushsides)
@ -824,6 +822,8 @@ CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
for (i = 0; i < brush->numsides; i++)
{
float d1, dist;
if (((brush->firstbrushside + i) < 0) ||
((brush->firstbrushside + i) >= (cmod->numbrushsides + EXTRA_LUMP_BRUSHSIDES)))
{
@ -844,7 +844,6 @@ CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
{
ofs[j] = maxs[j];
}
else
{
ofs[j] = mins[j];
@ -872,9 +871,8 @@ CM_TestBoxInBrush(vec3_t mins, vec3_t maxs, vec3_t p1,
static void
CM_TraceToLeaf(int leafnum)
{
int k, maxleaf, brushnum;
cleaf_t *leaf;
cbrush_t *b;
const cleaf_t *leaf;
int k, maxleaf;
if (leafnum >= (cmod->numleafs + EXTRA_LUMP_LEAFS) || leafnum < 0)
{
@ -898,6 +896,9 @@ CM_TraceToLeaf(int leafnum)
/* trace line against all brushes in the leaf */
for (k = 0; k < leaf->numleafbrushes; k++)
{
int brushnum;
cbrush_t *b;
brushnum = cmod->map_leafbrushes[leaf->firstleafbrush + k];
if (brushnum < 0 || brushnum >= (cmod->numbrushes + EXTRA_LUMP_BRUSHES))
@ -932,9 +933,8 @@ CM_TraceToLeaf(int leafnum)
static void
CM_TestInLeaf(int leafnum)
{
int k, maxleaf, brushnum;
cleaf_t *leaf;
cbrush_t *b;
const cleaf_t *leaf;
int k, maxleaf;
if (leafnum > (cmod->numleafs + EXTRA_LUMP_LEAFS) || leafnum < 0)
{
@ -958,6 +958,9 @@ CM_TestInLeaf(int leafnum)
/* trace line against all brushes in the leaf */
for (k = 0; k < leaf->numleafbrushes; k++)
{
int brushnum;
cbrush_t *b;
brushnum = cmod->map_leafbrushes[leaf->firstleafbrush + k];
if (brushnum < 0 || brushnum >= (cmod->numbrushes + EXTRA_LUMP_BRUSHES))
@ -1131,8 +1134,6 @@ trace_t
CM_BoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs,
int headnode, int brushmask)
{
int i;
checkcount++; /* for multi-check avoidance */
#ifndef DEDICATED_ONLY
@ -1212,9 +1213,10 @@ CM_BoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs,
{
VectorCopy(end, trace_trace.endpos);
}
else
{
int i;
for (i = 0; i < 3; i++)
{
trace_trace.endpos[i] = start[i] + trace_trace.fraction *
@ -1233,12 +1235,11 @@ trace_t
CM_TransformedBoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs,
int headnode, int brushmask, vec3_t origin, vec3_t angles)
{
trace_t trace;
vec3_t start_l, end_l;
vec3_t a;
vec3_t forward, right, up;
vec3_t temp;
vec3_t start_l, end_l;
qboolean rotated;
trace_t trace;
vec3_t temp;
/* subtract origin offset */
VectorSubtract(start, origin, start_l);
@ -1250,7 +1251,6 @@ CM_TransformedBoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs,
{
rotated = true;
}
else
{
rotated = false;
@ -1276,6 +1276,8 @@ CM_TransformedBoxTrace(vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs,
if (rotated && (trace.fraction != 1.0))
{
vec3_t a;
VectorNegate(angles, a);
AngleVectors(a, forward, right, up);
@ -1804,8 +1806,8 @@ static void
CMod_LoadAreaPortals(const char *name, dareaportal_t **map_areaportals, qboolean **portalopen,
int *numareaportals, const byte *cmod_base, const lump_t *l)
{
const dareaportal_t *in;
dareaportal_t *out;
dareaportal_t *in;
int count;
in = (void *)(cmod_base + l->fileofs);
@ -1925,9 +1927,9 @@ static void
CM_LoadCachedMap(const char *name, model_t *mod)
{
int i, length, hunkSize = 0;
const byte *cmod_base;
dheader_t header;
unsigned *buf;
byte *cmod_base;
length = FS_LoadFile(name, (void **)&buf);

View file

@ -405,7 +405,7 @@ void Cmd_AddCommand(const char *cmd_name, xcommand_t function);
/* as a clc_stringcmd instead of executed locally */
void Cmd_RemoveCommand(const char *cmd_name);
qboolean Cmd_Exists(char *cmd_name);
qboolean Cmd_Exists(const char *cmd_name);
/* used by the cvar code to check for cvar / command name overlap */

View file

@ -277,7 +277,7 @@ void AngleVectors2(const vec3_t value1, vec3_t angles);
int BoxOnPlaneSide(const vec3_t emins, const vec3_t emaxs, const struct cplane_s *plane);
float anglemod(float a);
float Q_fabs(float f);
float LerpAngle(float a1, float a2, float frac);
float LerpAngle(float a2, float a1, float frac);
int BoxOnPlaneSide2(const vec3_t emins, const vec3_t emaxs, const struct cplane_s *p);
#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \

View file

@ -133,7 +133,6 @@ AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
void
AngleVectors2(const vec3_t value1, vec3_t angles)
{
float forward;
float yaw, pitch;
if ((value1[1] == 0) && (value1[0] == 0))
@ -152,6 +151,8 @@ AngleVectors2(const vec3_t value1, vec3_t angles)
}
else
{
float forward;
if (value1[0])
{
yaw = ((float)atan2(value1[1], value1[0]) * 180 / M_PI);
@ -470,10 +471,11 @@ void
AddPointToBounds(const vec3_t v, vec3_t mins, vec3_t maxs)
{
int i;
vec_t val;
for (i = 0; i < 3; i++)
{
vec_t val;
val = v[i];
if (val < mins[i])
@ -502,13 +504,15 @@ VectorCompare(const vec3_t v1, const vec3_t v2)
vec_t
VectorNormalize(vec3_t v)
{
float length, ilength;
float length;
length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
length = (float)sqrt(length);
if (length)
{
float ilength;
ilength = 1 / length;
v[0] *= ilength;
v[1] *= ilength;
@ -1033,10 +1037,12 @@ Q_stricmp(const char *s1, const char *s2)
int
Q_strncasecmp(const char *s1, const char *s2, int n)
{
int c1, c2;
int c1;
do
{
int c2;
c1 = *s1++;
c2 = *s2++;
@ -1272,10 +1278,7 @@ Info_ValueForKey(char *s, const char *key)
void
Info_RemoveKey(char *s, const char *key)
{
char *start;
char pkey[512];
char value[512];
char *o;
char pkey[512], value[512];
if (strstr(key, "\\"))
{
@ -1284,6 +1287,8 @@ Info_RemoveKey(char *s, const char *key)
while (1)
{
char *start, *o;
start = s;
if (*s == '\\')
@ -1351,9 +1356,9 @@ Info_Validate(const char *s)
void
Info_SetValueForKey(char *s, const char *key, const char *value)
{
char newi[MAX_INFO_STRING], *v;
int c;
int maxsize = MAX_INFO_STRING;
char newi[MAX_INFO_STRING];
const char *v;
if (!key)
{
@ -1405,6 +1410,8 @@ Info_SetValueForKey(char *s, const char *key, const char *value)
while (*v)
{
int c;
c = *v++;
c &= 127; /* strip high bits */