Fix cppcheck warnings

src/common/cvar.c:160 Logical disjunction always evaluates to true: c >= '0' || c <= '9'. Are these conditions necessary? Did you intend to use && instead? Are the numbers correct? Are you comparing the correct variables?
src/common/cvar.c:141 The scope of the variable 'c' can be reduced.
src/common/cvar.c:517 The scope of the variable 'c' can be reduced.
src/common/shared/shared.c:1359 Either the condition '!value' is redundant or there is possible null pointer dereference: value.
src/common/shared/shared.c:1371 Either the condition '!value' is redundant or there is possible null pointer dereference: value.
src/common/shared/shared.c:1377 Either the condition '!value' is redundant or there is possible null pointer dereference: value.
src/client/refresh/soft/sw_main.c:1531 Variable 'err' is assigned a value that is never used.
This commit is contained in:
Denis Pauk 2020-12-17 22:49:03 +02:00
parent a4181a0bdb
commit 3418280b06
3 changed files with 31 additions and 22 deletions

View file

@ -1528,7 +1528,7 @@ RE_SetMode(void)
}
/* try setting it back to something safe */
if ((err = SWimp_SetMode(&vid.width, &vid.height, sw_state.prev_mode, 0)) != rserr_ok)
if (SWimp_SetMode(&vid.width, &vid.height, sw_state.prev_mode, 0) != rserr_ok)
{
R_Printf(PRINT_ALL, "%s() - could not revert to safe mode\n", __func__);
return false;

View file

@ -138,32 +138,34 @@ Cvar_FindVar(const char *var_name)
static qboolean
Cvar_IsFloat(const char *s)
{
int c, dot = '.';
int dot = '.';
if (*s == '-')
if (*s == '-')
{
s++;
}
s++;
}
if (!*s)
if (!*s)
{
return false;
}
return false;
}
do {
c = *s++;
do {
int c;
if (c == dot)
c = *s++;
if (c == dot)
{
dot = 0;
}
else if (!(c >= '0' || c <= '9'))
dot = 0;
}
else if (c < '0' || c > '9')
{
return false;
}
} while (*s);
return false;
}
} while (*s);
return true;
return true;
}
float
@ -514,7 +516,7 @@ void
Cvar_Set_f(void)
{
char *firstarg;
int c, flags, i;
int c, i;
c = Cmd_Argc();
@ -537,6 +539,8 @@ Cvar_Set_f(void)
if (c == 4)
{
int flags;
if (!strcmp(Cmd_Argv(3), "u"))
{
flags = CVAR_USERINFO;

View file

@ -1356,7 +1356,12 @@ Info_SetValueForKey(char *s, char *key, char *value)
int c;
int maxsize = MAX_INFO_STRING;
if (strstr(key, "\\") || strstr(value, "\\"))
if (!key)
{
return;
}
if (strstr(key, "\\") || (value && strstr(value, "\\")))
{
Com_Printf("Can't use keys or values with a \\\n");
return;
@ -1368,13 +1373,13 @@ Info_SetValueForKey(char *s, char *key, char *value)
return;
}
if (strstr(key, "\"") || strstr(value, "\""))
if (strstr(key, "\"") || (value && strstr(value, "\"")))
{
Com_Printf("Can't use keys or values with a \"\n");
return;
}
if ((strlen(key) > MAX_INFO_KEY - 1) || (strlen(value) > MAX_INFO_KEY - 1))
if ((strlen(key) > MAX_INFO_KEY - 1) || (value && (strlen(value) > MAX_INFO_KEY - 1)))
{
Com_Printf("Keys and values must be < 64 characters.\n");
return;