mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 15:21:44 +00:00
cppcheck fixes.
In src/backends/unix/network.c: * line 181: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? * line 276: The scope of the variable 'tmp' can be reduced. * line 665: The scope of the variable 'mcast_addr' can be reduced. * line 665: The scope of the variable 'mcast_port' can be reduced. * line 666: The scope of the variable 'error' can be reduced. * line 775: The scope of the variable 'i' can be reduced. In src/backends/windows/network.c: * line 186: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? * line 287: The scope of the variable 'tmp' can be reduced. * line 707: The scope of the variable 'mcast_addr' can be reduced. * line 707: The scope of the variable 'mcast_port' can be reduced. * line 1049: The scope of the variable 'err' can be reduced. * line 1163: The scope of the variable 'i' can be reduced. In src/client/menu/menu.c arrayIndexOutOfBounds: * line 1921: Array 'creditsIndex[256]' accessed at index 256, which is out of bounds. variableScope: * line 332: The scope of the variable 'item' can be reduced. * line 533: The scope of the variable 'x' can be reduced. * line 533: The scope of the variable 'y' can be reduced. * line 838: The scope of the variable 'b' can be reduced. * line 864: The scope of the variable 'b' can be reduced. * line 1910: The scope of the variable 'n' can be reduced. * line 2199: The scope of the variable 'str' can be reduced. * line 2812: The scope of the variable 'length' can be reduced. * line 2813: The scope of the variable 'i' can be reduced. * line 3838: The scope of the variable 'c' can be reduced. * line 4112: The scope of the variable 'scratch' can be reduced. * line 4181: The scope of the variable 'i' can be reduced. * line 4345: The scope of the variable 's' can be reduced. In src/game/player/hud.c arrayIndexOutOfBounds: * line 132: Array itemlist[43] accessed at index 255 which is out of bounds. Itemlist assigned only once, and has only 43 items, better ignore unexisted items. variableScope: * line 82: The scope of the variable 'n' can be reduced. * line 217: The scope of the variable 'x' can be reduced. * line 217: The scope of the variable 'y' can be reduced. * line 218: The scope of the variable 'cl' can be reduced. * line 583: The scope of the variable 'cl' can be reduced.
This commit is contained in:
parent
2bf45a4750
commit
1b2708c06e
5 changed files with 95 additions and 71 deletions
|
@ -176,10 +176,6 @@ SockadrToNetadr(struct sockaddr_storage *s, netadr_t *a)
|
|||
a->scope_id = s6->sin6_scope_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -273,7 +269,7 @@ NET_CompareBaseAdr(netadr_t a, netadr_t b)
|
|||
char *
|
||||
NET_BaseAdrToString(netadr_t a)
|
||||
{
|
||||
static char s[64], tmp[64];
|
||||
static char s[64];
|
||||
struct sockaddr_storage ss;
|
||||
struct sockaddr_in6 *s6;
|
||||
|
||||
|
@ -332,6 +328,8 @@ NET_BaseAdrToString(netadr_t a)
|
|||
IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)&ss)->
|
||||
sin6_addr))
|
||||
{
|
||||
char tmp[64];
|
||||
|
||||
/* If the address is multicast (link) or a
|
||||
link-local, need to carry the scope. The string
|
||||
format of the IPv6 address is used by the
|
||||
|
@ -662,11 +660,13 @@ NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to)
|
|||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res;
|
||||
char tmp[128], mcast_addr[128], mcast_port[10];
|
||||
int error;
|
||||
char tmp[128];
|
||||
|
||||
if (multicast_interface != NULL)
|
||||
{
|
||||
int error;
|
||||
char mcast_addr[128], mcast_port[10];
|
||||
|
||||
/* Do a getnameinfo/getaddrinfo cycle
|
||||
to calculate the scope_id of the
|
||||
multicast address. getaddrinfo is
|
||||
|
@ -772,10 +772,10 @@ NET_OpenIP(void)
|
|||
void
|
||||
NET_Config(qboolean multiplayer)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!multiplayer)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* shut down any existing sockets */
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
|
|
|
@ -181,10 +181,6 @@ SockadrToNetadr(struct sockaddr_storage *s, netadr_t *a)
|
|||
a->scope_id = s6->sin6_scope_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
qboolean
|
||||
|
@ -284,7 +280,7 @@ NET_CompareBaseAdr(netadr_t a, netadr_t b)
|
|||
char *
|
||||
NET_BaseAdrToString(netadr_t a)
|
||||
{
|
||||
static char s[64], tmp[64];
|
||||
static char s[64];
|
||||
struct sockaddr_storage ss;
|
||||
struct sockaddr_in6 *s6;
|
||||
|
||||
|
@ -342,6 +338,8 @@ NET_BaseAdrToString(netadr_t a)
|
|||
already return scoped IPv6 address. */
|
||||
if (strchr(s, '%') == NULL)
|
||||
{
|
||||
char tmp[64];
|
||||
|
||||
Com_sprintf(tmp, sizeof(tmp), "%s%%%d", s,
|
||||
s6->sin6_scope_id);
|
||||
memcpy(s, tmp, sizeof(s));
|
||||
|
@ -704,7 +702,7 @@ NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to)
|
|||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res;
|
||||
char tmp[128], mcast_addr[128], mcast_port[10];
|
||||
char tmp[128];
|
||||
int error;
|
||||
|
||||
/* Do a getnameinfo/getaddrinfo cycle
|
||||
|
@ -726,6 +724,8 @@ NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to)
|
|||
|
||||
if (multicast_interface != NULL)
|
||||
{
|
||||
char mcast_addr[128], mcast_port[10]
|
||||
|
||||
Com_sprintf(mcast_addr, sizeof(mcast_addr), "%s", tmp);
|
||||
Com_sprintf(mcast_port, sizeof(mcast_port), "%d",
|
||||
ntohs(s6->sin6_port));
|
||||
|
@ -1046,10 +1046,11 @@ NET_IPXSocket(int port)
|
|||
int newsocket;
|
||||
struct sockaddr_ipx address;
|
||||
unsigned long t = 1;
|
||||
int err;
|
||||
|
||||
if ((newsocket = socket(PF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == -1)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = WSAGetLastError();
|
||||
|
||||
if (err != WSAEAFNOSUPPORT)
|
||||
|
@ -1160,7 +1161,6 @@ NET_OpenIPX(void)
|
|||
void
|
||||
NET_Config(qboolean multiplayer)
|
||||
{
|
||||
int i;
|
||||
static qboolean old_config;
|
||||
|
||||
if (old_config == multiplayer)
|
||||
|
@ -1172,6 +1172,8 @@ NET_Config(qboolean multiplayer)
|
|||
|
||||
if (!multiplayer)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* shut down any existing sockets */
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
|
|
|
@ -329,11 +329,12 @@ const char *
|
|||
Default_MenuKey(menuframework_s *m, int key)
|
||||
{
|
||||
const char *sound = NULL;
|
||||
menucommon_s *item;
|
||||
int menu_key = Key_GetMenuKey(key);
|
||||
|
||||
if (m)
|
||||
{
|
||||
menucommon_s *item;
|
||||
|
||||
if ((item = Menu_ItemAtCursor(m)) != 0)
|
||||
{
|
||||
if (item->type == MTYPE_FIELD)
|
||||
|
@ -433,13 +434,14 @@ M_Print(int x, int y, char *str)
|
|||
}
|
||||
}
|
||||
|
||||
/* Unsused, left for backward compability */
|
||||
void
|
||||
M_DrawPic(int x, int y, char *pic)
|
||||
{
|
||||
float scale = SCR_GetMenuScale();
|
||||
|
||||
Draw_PicScaled((x + ((viddef.width - 320) >> 1)) * scale,
|
||||
(y + ((viddef.height - 240) >> 1)) * scale, pic, scale);
|
||||
Draw_PicScaled((x + ((viddef.width - 320) >> 1)) * scale,
|
||||
(y + ((viddef.height - 240) >> 1)) * scale, pic, scale);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -530,7 +532,7 @@ static int m_popup_endtime;
|
|||
static void
|
||||
M_Popup(void)
|
||||
{
|
||||
int x, y, width, lines;
|
||||
int width, lines;
|
||||
int n;
|
||||
char *str;
|
||||
|
||||
|
@ -569,6 +571,7 @@ M_Popup(void)
|
|||
|
||||
if (width)
|
||||
{
|
||||
int x, y;
|
||||
width += 2;
|
||||
|
||||
x = (320 - (width + 2) * 8) / 2;
|
||||
|
@ -835,12 +838,12 @@ M_UnbindCommand(char *command)
|
|||
{
|
||||
int j;
|
||||
int l;
|
||||
char *b;
|
||||
|
||||
l = strlen(command);
|
||||
|
||||
for (j = 0; j < 256; j++)
|
||||
{
|
||||
char *b;
|
||||
b = keybindings[j];
|
||||
|
||||
if (!b)
|
||||
|
@ -861,7 +864,6 @@ M_FindKeysForCommand(char *command, int *twokeys)
|
|||
int count;
|
||||
int j;
|
||||
int l;
|
||||
char *b;
|
||||
|
||||
twokeys[0] = twokeys[1] = -1;
|
||||
l = strlen(command);
|
||||
|
@ -869,6 +871,7 @@ M_FindKeysForCommand(char *command, int *twokeys)
|
|||
|
||||
for (j = 0; j < 256; j++)
|
||||
{
|
||||
char *b;
|
||||
b = keybindings[j];
|
||||
|
||||
if (!b)
|
||||
|
@ -1474,9 +1477,10 @@ M_Menu_Video_f(void)
|
|||
* END GAME MENU
|
||||
*/
|
||||
|
||||
#define CREDITS_SIZE 256
|
||||
static int credits_start_time;
|
||||
static const char **credits;
|
||||
static char *creditsIndex[256];
|
||||
static char *creditsIndex[CREDITS_SIZE];
|
||||
static char *creditsBuffer;
|
||||
static const char *idcredits[] = {
|
||||
"+QUAKE II BY ID SOFTWARE",
|
||||
|
@ -1907,7 +1911,6 @@ M_Credits_Key(int key)
|
|||
static void
|
||||
M_Menu_Credits_f(void)
|
||||
{
|
||||
int n;
|
||||
int count;
|
||||
char *p;
|
||||
|
||||
|
@ -1916,9 +1919,11 @@ M_Menu_Credits_f(void)
|
|||
|
||||
if (count != -1)
|
||||
{
|
||||
int n;
|
||||
p = creditsBuffer;
|
||||
|
||||
for (n = 0; n < 255; n++)
|
||||
// CREDITS_SIZE - 1 - last pointer should be NULL
|
||||
for (n = 0; n < CREDITS_SIZE - 1; n++)
|
||||
{
|
||||
creditsIndex[n] = p;
|
||||
|
||||
|
@ -1946,11 +1951,14 @@ M_Menu_Credits_f(void)
|
|||
|
||||
if (--count == 0)
|
||||
{
|
||||
// no credits any more
|
||||
// move one step futher for set NULL
|
||||
n ++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
creditsIndex[++n] = 0;
|
||||
creditsIndex[n] = 0;
|
||||
credits = (const char **)creditsIndex;
|
||||
}
|
||||
else
|
||||
|
@ -2196,7 +2204,6 @@ static void
|
|||
LoadSave_AdjustPage(int dir)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
m_loadsave_page += dir;
|
||||
|
||||
|
@ -2213,6 +2220,7 @@ LoadSave_AdjustPage(int dir)
|
|||
|
||||
for (i = 0; i < MAX_SAVEPAGES; i++)
|
||||
{
|
||||
char *str;
|
||||
str = va("%c%d%c",
|
||||
i == m_loadsave_page ? '[' : ' ',
|
||||
i + 1,
|
||||
|
@ -2817,13 +2825,13 @@ StartServer_MenuInit(void)
|
|||
|
||||
char *buffer;
|
||||
char *s;
|
||||
int length;
|
||||
int i;
|
||||
float scale = SCR_GetMenuScale();
|
||||
|
||||
/* initialize list of maps once, reuse it afterwards (=> it isn't freed) */
|
||||
if (mapnames == NULL)
|
||||
{
|
||||
int i, length;
|
||||
|
||||
/* load the list of map names */
|
||||
if ((length = FS_LoadFile("maps.lst", (void **)&buffer)) == -1)
|
||||
{
|
||||
|
@ -3865,7 +3873,6 @@ PlayerConfig_ScanDirectories(void)
|
|||
for (i = 0; i < npms; i++)
|
||||
{
|
||||
int k, s;
|
||||
char *a, *b, *c;
|
||||
char **pcxnames;
|
||||
char **skinnames;
|
||||
fileHandle_t f;
|
||||
|
@ -3926,12 +3933,11 @@ PlayerConfig_ScanDirectories(void)
|
|||
/* copy the valid skins */
|
||||
for (s = 0, k = 0; k < npcxfiles - 1; k++)
|
||||
{
|
||||
char *a, *b, *c;
|
||||
|
||||
if (!strstr(pcxnames[k], "_i.pcx"))
|
||||
{
|
||||
if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles - 1))
|
||||
{
|
||||
char *a, *b, *c;
|
||||
a = strrchr(pcxnames[k], '/');
|
||||
b = strrchr(pcxnames[k], '\\');
|
||||
|
||||
|
@ -3962,23 +3968,25 @@ PlayerConfig_ScanDirectories(void)
|
|||
s_pmi[s_numplayermodels].nskins = nskins;
|
||||
s_pmi[s_numplayermodels].skindisplaynames = skinnames;
|
||||
|
||||
/* make short name for the model */
|
||||
a = strrchr(dirnames[i], '/');
|
||||
b = strrchr(dirnames[i], '\\');
|
||||
|
||||
if (a > b)
|
||||
{
|
||||
c = a;
|
||||
char *a, *b, *c;
|
||||
/* make short name for the model */
|
||||
a = strrchr(dirnames[i], '/');
|
||||
b = strrchr(dirnames[i], '\\');
|
||||
|
||||
if (a > b)
|
||||
{
|
||||
c = a;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
c = b;
|
||||
}
|
||||
|
||||
Q_strlcpy(s_pmi[s_numplayermodels].displayname, c + 1, sizeof(s_pmi[s_numplayermodels].displayname));
|
||||
Q_strlcpy(s_pmi[s_numplayermodels].directory, c + 1, sizeof(s_pmi[s_numplayermodels].directory));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
c = b;
|
||||
}
|
||||
|
||||
Q_strlcpy(s_pmi[s_numplayermodels].displayname, c + 1, sizeof(s_pmi[s_numplayermodels].displayname));
|
||||
Q_strlcpy(s_pmi[s_numplayermodels].directory, c + 1, sizeof(s_pmi[s_numplayermodels].directory));
|
||||
|
||||
FreeFileList(pcxnames, npcxfiles);
|
||||
|
||||
s_numplayermodels++;
|
||||
|
@ -4200,8 +4208,7 @@ static void
|
|||
PlayerConfig_MenuDraw(void)
|
||||
{
|
||||
refdef_t refdef;
|
||||
char scratch[MAX_QPATH];
|
||||
float scale = SCR_GetMenuScale();
|
||||
float scale = SCR_GetMenuScale();
|
||||
|
||||
memset(&refdef, 0, sizeof(refdef));
|
||||
|
||||
|
@ -4217,6 +4224,7 @@ PlayerConfig_MenuDraw(void)
|
|||
{
|
||||
static int yaw;
|
||||
entity_t entity;
|
||||
char scratch[MAX_QPATH];
|
||||
|
||||
memset(&entity, 0, sizeof(entity));
|
||||
|
||||
|
@ -4269,11 +4277,10 @@ PlayerConfig_MenuDraw(void)
|
|||
static const char *
|
||||
PlayerConfig_MenuKey(int key)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (key == K_ESCAPE)
|
||||
{
|
||||
char scratch[1024];
|
||||
int i;
|
||||
|
||||
Cvar_Set("name", s_player_name_field.buffer);
|
||||
|
||||
|
@ -4433,10 +4440,9 @@ M_Draw(void)
|
|||
void
|
||||
M_Keydown(int key)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
if (m_keyfunc)
|
||||
{
|
||||
const char *s;
|
||||
if ((s = m_keyfunc(key)) != 0)
|
||||
{
|
||||
S_StartLocalSound((char *)s);
|
||||
|
|
|
@ -1655,7 +1655,7 @@ SpawnItem(edict_t *ent, gitem_t *item)
|
|||
|
||||
/* ====================================================================== */
|
||||
|
||||
gitem_t itemlist[] = {
|
||||
static const gitem_t gameitemlist[] = {
|
||||
{
|
||||
NULL
|
||||
}, /* leave index 0 alone */
|
||||
|
@ -2576,6 +2576,8 @@ gitem_t itemlist[] = {
|
|||
{NULL}
|
||||
};
|
||||
|
||||
gitem_t itemlist[MAX_ITEMS];
|
||||
|
||||
/*
|
||||
* QUAKED item_health (.3 .3 1) (-16 -16 -16) (16 16 16)
|
||||
*/
|
||||
|
@ -2673,7 +2675,9 @@ SP_item_health_mega(edict_t *self)
|
|||
void
|
||||
InitItems(void)
|
||||
{
|
||||
game.num_items = sizeof(itemlist) / sizeof(itemlist[0]) - 1;
|
||||
memset(itemlist, 0, sizeof(itemlist));
|
||||
memcpy(itemlist, gameitemlist, sizeof(gameitemlist));
|
||||
game.num_items = sizeof(gameitemlist) / sizeof(gameitemlist[0]) - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -79,8 +79,8 @@ MoveClientToIntermission(edict_t *ent)
|
|||
void
|
||||
BeginIntermission(edict_t *targ)
|
||||
{
|
||||
int i, n;
|
||||
edict_t *ent, *client;
|
||||
int i;
|
||||
edict_t *ent;
|
||||
|
||||
if (!targ)
|
||||
{
|
||||
|
@ -97,6 +97,8 @@ BeginIntermission(edict_t *targ)
|
|||
/* respawn any dead clients */
|
||||
for (i = 0; i < maxclients->value; i++)
|
||||
{
|
||||
edict_t *client;
|
||||
|
||||
client = g_edicts + 1 + i;
|
||||
|
||||
if (!client->inuse)
|
||||
|
@ -119,6 +121,9 @@ BeginIntermission(edict_t *targ)
|
|||
{
|
||||
for (i = 0; i < maxclients->value; i++)
|
||||
{
|
||||
int n;
|
||||
edict_t *client;
|
||||
|
||||
client = g_edicts + 1 + i;
|
||||
|
||||
if (!client->inuse)
|
||||
|
@ -193,6 +198,8 @@ BeginIntermission(edict_t *targ)
|
|||
/* move all clients to the intermission point */
|
||||
for (i = 0; i < maxclients->value; i++)
|
||||
{
|
||||
edict_t *client;
|
||||
|
||||
client = g_edicts + 1 + i;
|
||||
|
||||
if (!client->inuse)
|
||||
|
@ -210,14 +217,10 @@ DeathmatchScoreboardMessage(edict_t *ent, edict_t *killer)
|
|||
char entry[1024];
|
||||
char string[1400];
|
||||
int stringlength;
|
||||
int i, j, k;
|
||||
int i;
|
||||
int sorted[MAX_CLIENTS];
|
||||
int sortedscores[MAX_CLIENTS];
|
||||
int score, total;
|
||||
int x, y;
|
||||
gclient_t *cl;
|
||||
edict_t *cl_ent;
|
||||
char *tag;
|
||||
int total;
|
||||
|
||||
if (!ent) /* killer can be NULL */
|
||||
{
|
||||
|
@ -229,6 +232,9 @@ DeathmatchScoreboardMessage(edict_t *ent, edict_t *killer)
|
|||
|
||||
for (i = 0; i < game.maxclients; i++)
|
||||
{
|
||||
int k, j, score;
|
||||
edict_t *cl_ent;
|
||||
|
||||
cl_ent = g_edicts + 1 + i;
|
||||
|
||||
if (!cl_ent->inuse || game.clients[i].resp.spectator)
|
||||
|
@ -270,6 +276,11 @@ DeathmatchScoreboardMessage(edict_t *ent, edict_t *killer)
|
|||
|
||||
for (i = 0; i < total; i++)
|
||||
{
|
||||
char *tag;
|
||||
int x, y, j;
|
||||
gclient_t *cl;
|
||||
edict_t *cl_ent;
|
||||
|
||||
cl = &game.clients[sorted[i]];
|
||||
cl_ent = g_edicts + 1 + sorted[i];
|
||||
|
||||
|
@ -580,7 +591,6 @@ void
|
|||
G_CheckChaseStats(edict_t *ent)
|
||||
{
|
||||
int i;
|
||||
gclient_t *cl;
|
||||
|
||||
if (!ent)
|
||||
{
|
||||
|
@ -589,6 +599,8 @@ G_CheckChaseStats(edict_t *ent)
|
|||
|
||||
for (i = 1; i <= maxclients->value; i++)
|
||||
{
|
||||
gclient_t *cl;
|
||||
|
||||
cl = g_edicts[i].client;
|
||||
|
||||
if (!g_edicts[i].inuse || (cl->chase_target != ent))
|
||||
|
|
Loading…
Reference in a new issue