Fixes for PVS Studio warnings: most of src/common/

except for frame.c, I'd like Yamagi's input on that
This commit is contained in:
Daniel Gibson 2019-07-21 03:14:21 +02:00
parent 90d0fe07e2
commit d368a67976
4 changed files with 35 additions and 14 deletions

View file

@ -1673,8 +1673,8 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
map_noareas = Cvar_Get("map_noareas", "0", 0);
if (!strcmp(map_name,
name) && (clientload || !Cvar_VariableValue("flushmap")))
if (strcmp(map_name, name) == 0
&& (clientload || !Cvar_VariableValue("flushmap")))
{
*checksum = last_checksum;
@ -1697,7 +1697,7 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
map_entitystring[0] = 0;
map_name[0] = 0;
if (!name || !name[0])
if (!name[0])
{
numleafs = 1;
numclusters = 1;

View file

@ -482,11 +482,6 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
handle->file = Q_fopen(path, "rb");
}
if (!handle->file)
{
continue;
}
if (handle->file)
{
if (fs_debug->value)
@ -1001,6 +996,10 @@ FS_ListFiles(char *findname, int *numfiles,
/* Allocate the list. */
list = calloc(nfiles, sizeof(char *));
if(list == NULL)
{
Com_Error(ERR_FATAL, "calloc() failed in %s() - out of memory?!\n", __func__);
}
/* Fill the list. */
s = Sys_FindFirst(findname, musthave, canthave);
@ -1103,6 +1102,10 @@ FS_ListFiles2(char *findname, int *numfiles,
nfiles = 0;
list = malloc(sizeof(char *));
if(list == NULL)
{
Com_Error(ERR_FATAL, "malloc() failed in %s() - out of memory?!\n", __func__);
}
for (search = fs_searchPaths; search != NULL; search = search->next)
{
@ -1129,6 +1132,10 @@ FS_ListFiles2(char *findname, int *numfiles,
nfiles += j;
list = realloc(list, nfiles * sizeof(char *));
if(list == NULL)
{
Com_Error(ERR_FATAL, "realloc() failed in %s() - out of memory?!\n", __func__);
}
for (i = 0, j = nfiles - j; i < search->pack->numFiles; i++)
{
@ -1153,6 +1160,10 @@ FS_ListFiles2(char *findname, int *numfiles,
tmpnfiles--;
nfiles += tmpnfiles;
list = realloc(list, nfiles * sizeof(char *));
if(list == NULL)
{
Com_Error(ERR_FATAL, "realloc() failed in %s() - out of memory?!\n", __func__);
}
for (i = 0, j = nfiles - tmpnfiles; i < tmpnfiles; i++, j++)
{
@ -1189,6 +1200,10 @@ FS_ListFiles2(char *findname, int *numfiles,
{
nfiles -= tmpnfiles;
tmplist = malloc(nfiles * sizeof(char *));
if(tmplist == NULL)
{
Com_Error(ERR_FATAL, "malloc(nfiles * sizeof(char *)) failed in %s() - out of memory?!\n", __func__);
}
for (i = 0, j = 0; i < nfiles + tmpnfiles; i++)
{
@ -1207,6 +1222,10 @@ FS_ListFiles2(char *findname, int *numfiles,
{
nfiles++;
list = realloc(list, nfiles * sizeof(char *));
if(list == NULL)
{
Com_Error(ERR_FATAL, "realloc() failed in %s() - out of memory?!\n", __func__);
}
list[nfiles - 1] = NULL;
}
@ -1620,7 +1639,7 @@ FS_BuildGameSpecificSearchPath(char *dir)
}
// The game was reset to baseq2. Nothing to do here.
if ((Q_stricmp(dir, BASEDIRNAME) == 0) || (*dir == 0)) {
if (Q_stricmp(dir, BASEDIRNAME) == 0) {
Cvar_FullSet("gamedir", "", CVAR_SERVERINFO | CVAR_NOSET);
Cvar_FullSet("game", "", CVAR_LATCH | CVAR_SERVERINFO);

View file

@ -75,7 +75,7 @@ RotatePointAroundVector(vec3_t dst, const vec3_t dir,
im[2][1] = m[1][2];
memset(zrot, 0, sizeof(zrot));
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
zrot[2][2] = 1.0F;
zrot[0][0] = (float)cos(DEG2RAD(degrees));
zrot[0][1] = (float)sin(DEG2RAD(degrees));
@ -867,9 +867,12 @@ void
Swap_Init(void)
{
byte swaptest[2] = {1, 0};
short swapTestShort;
assert(sizeof(short) == 2);
memcpy(&swapTestShort, swaptest, 2);
/* set the byte swapping variables in a portable manner */
if (*(short *)swaptest == 1)
if (swapTestShort == 1)
{
bigendien = false;
_BigShort = ShortSwap;
@ -892,7 +895,7 @@ Swap_Init(void)
Com_Printf("Byte ordering: big endian\n\n");
}
if (LittleShort(*(short *)swaptest) != 1)
if (LittleShort(swapTestShort) != 1)
assert("Error in the endian conversion!");
}

View file

@ -41,9 +41,8 @@ Z_Free(void *ptr)
if (z->magic != Z_MAGIC)
{
printf("free: %p failed\n", ptr);
Com_Printf("ERROR: Z_free(%p) failed: bad magic\n", ptr);
abort();
Com_Error(ERR_FATAL, "Z_Free: bad magic");
}
z->prev->next = z->next;