Make static C code analysis tool little more happy(#426)

sw_image.c:
	203: The potential null pointer is passed into 'memcpy' function. Inspect the first argument. Check lines: 203, 192.
	368: The null pointer is passed into 'free' function. Inspect the first argument.
	401: Expression '!pic' is always false.
	401: There are two 'if' statements with identical conditional expressions. The first 'if' statement contains function return. This means that the second 'if' statement is senseless. Check lines: 394, 401.
	565: The potential null pointer is passed into 'memcpy' function. Inspect the first argument. Check lines: 565, 564.

sw_model.c:
	215: The 'model' pointer was used unsafely after it was verified against nullptr. Check lines: 210, 215.
	985: The 'header->lumps[12].filelen / sizeof (int)' expression was implicitly cast from 'size_t' type to 'float' type. Consider utilizing an explicit type cast to avoid the loss of a fractional part. An example: double A = (double)(X) / Y;.
	1277: Function 'RE_BeginRegistration' argument 1 names different: declaration 'map' definition 'model'.

sw_surf.c:
	239: There might be dereferencing of a potential null pointer 'sc_base'. Check lines: 239, 236.

sw_main.c:
	1345: The if condition is the same as the previous if condition
	1466: Function 'R_GammaCorrectAndSetPalette' argument 1 names different: declaration 'pal' definition 'palette'
	2063: The 'swap_buffers' pointer in the expression could be nullptr. In such case, resulting value of arithmetic operations on this pointer will be senseless and it should not be used. Check lines: 2063, 2061.

sw_aclip.c:
	180: Variable 'j' is reassigned a value before the old one has been used.

sw_alias.c:
	209: Function 'R_AliasTransformVector' argument 3 names different: declaration 'm' definition 'xf'.

sw_draw.c:
	78: Function 'RE_Draw_CharScaled' argument 3 names different: declaration 'c' definition 'num'.
	149: Function 'RE_Draw_GetPicSize' argument 3 names different: declaration 'name' definition 'pic'.
	173: The scope of the variable 'u' can be reduced.
	267: Function 'RE_Draw_PicScaled' argument 4 names different: declaration 'factor' definition 'scale'.

sw_scan.c
	593: Function 'D_DrawSpansPow2' argument 1 names different: declaration 'pspans' definition 'pspan'.
	745: Function 'D_DrawZSpans' argument 1 names different: declaration 'pspans' definition 'pspan'.
This commit is contained in:
Denis Pauk 2019-09-12 22:36:13 +03:00
parent 5d97bbff8a
commit 129da805a1
8 changed files with 51 additions and 27 deletions

View file

@ -358,8 +358,8 @@ extern float d_sdivzstepu, d_tdivzstepu;
extern float d_sdivzstepv, d_tdivzstepv;
extern float d_sdivzorigin, d_tdivzorigin;
void D_DrawSpansPow2(espan_t *pspans, float d_ziorigin, float d_zistepu, float d_zistepv);
void D_DrawZSpans(espan_t *pspans, float d_ziorigin, float d_zistepu, float d_zistepv);
void D_DrawSpansPow2(espan_t *pspan, float d_ziorigin, float d_zistepu, float d_zistepv);
void D_DrawZSpans(espan_t *pspan, float d_ziorigin, float d_zistepu, float d_zistepv);
void TurbulentPow2(espan_t *pspan, float d_ziorigin, float d_zistepu, float d_zistepv);
void NonTurbulentPow2(espan_t *pspan, float d_ziorigin, float d_zistepu, float d_zistepv);
@ -557,14 +557,14 @@ void Draw_InitLocal(void);
void R_InitCaches(void);
void D_FlushCaches(void);
void RE_BeginRegistration (char *map);
void RE_BeginRegistration (char *model);
struct model_s *RE_RegisterModel (char *name);
void RE_EndRegistration (void);
struct image_s *RE_Draw_FindPic (char *name);
void RE_Draw_GetPicSize (int *w, int *h, char *name);
void RE_Draw_PicScaled (int x, int y, char *name, float factor);
void RE_Draw_PicScaled (int x, int y, char *name, float scale);
void RE_Draw_StretchPic (int x, int y, int w, int h, char *name);
void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data);
void RE_Draw_CharScaled (int x, int y, int c, float scale);

View file

@ -177,7 +177,7 @@ R_AliasClip (const finalvert_t *in, finalvert_t *out, int flag, int count,
j = count-1;
k = 0;
for (i=0 ; i<count ; j = i, i++)
for (i=0 ; i<count ; i++)
{
int flags, oldflags;
@ -185,7 +185,10 @@ R_AliasClip (const finalvert_t *in, finalvert_t *out, int flag, int count,
flags = in[i].flags & flag;
if (flags && oldflags)
{
j = i;
continue;
}
if (oldflags ^ flags)
{
clip (&in[j], &in[i], &out[k]);
@ -205,6 +208,7 @@ R_AliasClip (const finalvert_t *in, finalvert_t *out, int flag, int count,
out[k] = in[i];
k++;
}
j = i;
}
return k;

View file

@ -58,7 +58,7 @@ static const float r_avertexnormals[NUMVERTEXNORMALS][3] = {
};
static void R_AliasTransformVector(const vec3_t in, vec3_t out, const float m[3][4]);
static void R_AliasTransformVector(const vec3_t in, vec3_t out, const float xf[3][4]);
static void R_AliasTransformFinalVerts(const entity_t *currententity, int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv );
void R_AliasProjectAndClipTestFinalVert(finalvert_t *fv);

View file

@ -75,7 +75,7 @@ smoothly scrolled off.
================
*/
void
RE_Draw_CharScaled(int x, int y, int num, float scale)
RE_Draw_CharScaled(int x, int y, int c, float scale)
{
pixel_t *dest;
byte *source;
@ -87,9 +87,9 @@ RE_Draw_CharScaled(int x, int y, int num, float scale)
if (iscale < 1)
return;
num &= 255;
c &= 255;
if (num == 32 || num == 32+128)
if (c == 32 || c == 32+128)
return;
if (y <= -8)
@ -98,8 +98,8 @@ RE_Draw_CharScaled(int x, int y, int num, float scale)
if ( ( y + 8 ) > vid.height ) // status text was missing in sw...
return;
row = num>>4;
col = num&15;
row = c>>4;
col = c&15;
source = draw_chars->pixels[0] + (row<<10) + (col<<3);
if (y < 0)
@ -146,11 +146,11 @@ RE_Draw_GetPicSize
=============
*/
void
RE_Draw_GetPicSize (int *w, int *h, char *pic)
RE_Draw_GetPicSize (int *w, int *h, char *name)
{
image_t *gl;
gl = RE_Draw_FindPic (pic);
gl = RE_Draw_FindPic (name);
if (!gl)
{
*w = *h = -1;
@ -170,7 +170,6 @@ RE_Draw_StretchPicImplementation (int x, int y, int w, int h, const image_t *pic
{
pixel_t *dest;
byte *source;
int v, u;
int height;
int skip;
@ -198,6 +197,8 @@ RE_Draw_StretchPicImplementation (int x, int y, int w, int h, const image_t *pic
if (w == pic->width)
{
int v;
for (v=0 ; v<height ; v++, dest += vid.width)
{
int sv = (skip + v)*pic->height/h;
@ -207,9 +208,10 @@ RE_Draw_StretchPicImplementation (int x, int y, int w, int h, const image_t *pic
}
else
{
int v;
for (v=0 ; v<height ; v++, dest += vid.width)
{
int f, fstep;
int f, fstep, u;
int sv = (skip + v)*pic->height/h;
source = pic->pixels[0] + sv*pic->width;
f = 0;

View file

@ -190,6 +190,12 @@ R_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type)
size = width * height;
full_size = R_GetImageMipsSize(size);
image->pixels[0] = malloc(full_size);
if (!image->pixels[0])
{
ri.Sys_Error(ERR_FATAL, "%s: Can't allocate image.", __func__);
// code never returns after ERR_FATAL
return NULL;
}
image->transparent = false;
for (i=0 ; i<size ; i++)
{
@ -363,7 +369,7 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
}
}
if (!pic)
if (pic)
{
free(pic);
}
@ -398,11 +404,8 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type)
{
free(palette);
}
if (!pic)
{
free(pic);
}
}
else if (strcmp(ext, "wal") == 0)
{
image = R_LoadWal(name, type);
@ -560,6 +563,8 @@ R_InitImages (void)
if ( !table16to8 )
{
ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/16to8.dat", __func__);
// code never returns after ERR_FATAL
return;
}
d_16to8table = malloc(0x10000);
memcpy(d_16to8table, table16to8, 0x10000);

View file

@ -1159,7 +1159,7 @@ R_EdgeDrawing (void)
//=======================================================================
static void R_GammaCorrectAndSetPalette(const unsigned char *pal);
static void R_GammaCorrectAndSetPalette(const unsigned char *palette);
/*
=============
@ -1267,7 +1267,7 @@ RE_RenderFrame (refdef_t *fd)
VectorCopy (fd->vieworg, r_refdef.vieworg);
VectorCopy (fd->viewangles, r_refdef.viewangles);
// compare current possition with old
// compare current position with old
if (!VectorCompareRound(fd->vieworg, lastvieworg) ||
!VectorCompare(fd->viewangles, lastviewangles))
{
@ -1278,7 +1278,7 @@ RE_RenderFrame (refdef_t *fd)
fastmoving = false;
}
// save possition for next check
// save position for next check
VectorCopy (fd->vieworg, lastvieworg);
VectorCopy (fd->viewangles, lastviewangles);
@ -1340,10 +1340,10 @@ RE_RenderFrame (refdef_t *fd)
D_WarpScreen ();
if (r_dspeeds->value)
{
da_time1 = SDL_GetTicks();
if (r_dspeeds->value)
da_time2 = SDL_GetTicks();
}
// Modify the palette (when taking hit or pickup item) so all colors are modified
R_CalcPalette ();
@ -2172,6 +2172,12 @@ SWimp_CreateRender(void)
{
swap_current = 0;
swap_buffers = malloc(vid.height * vid.width * sizeof(pixel_t) * 2);
if (!swap_buffers)
{
ri.Sys_Error(ERR_FATAL, "%s: Can't allocate swapbuffer.", __func__);
// code never returns after ERR_FATAL
return;
}
swap_frames[0] = swap_buffers;
swap_frames[1] = swap_buffers + vid.height * vid.width * sizeof(pixel_t);
vid_buffer = swap_frames[swap_current&1];

View file

@ -210,6 +210,7 @@ Mod_PointInLeaf (vec3_t p, model_t *model)
if (!model || !model->nodes)
{
ri.Sys_Error(ERR_DROP, "%s: bad model", __func__);
return NULL;
}
node = model->nodes;
@ -982,7 +983,7 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
int hunkSize = 0;
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_VERTEXES], sizeof(dvertex_t), sizeof(mvertex_t), 8);
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_EDGES], sizeof(dedge_t), sizeof(medge_t), 13);
float surfEdgeCount = header->lumps[LUMP_SURFEDGES].filelen/sizeof(int);
float surfEdgeCount = (float)header->lumps[LUMP_SURFEDGES].filelen / sizeof(int);
if(surfEdgeCount < MAX_MAP_SURFEDGES) // else it errors out later anyway
hunkSize += calcLumpHunkSize(&header->lumps[LUMP_SURFEDGES], sizeof(int), sizeof(int), 24);

View file

@ -234,6 +234,12 @@ R_InitCaches (void)
sc_size = size;
sc_base = (surfcache_t *)malloc(size);
if (!sc_base)
{
ri.Sys_Error(ERR_FATAL, "%s: Can't allocate cache.", __func__);
// code never returns after ERR_FATAL
return;
}
sc_rover = sc_base;
sc_base->next = NULL;