Merge pull request #11 from NeonKnightOA/cppcheckfixes

Fixed many issues pointed out by cppcheck.
This commit is contained in:
Yamagi 2020-04-21 12:48:32 +02:00 committed by GitHub
commit a047746337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 52 additions and 89 deletions

View File

@ -573,15 +573,9 @@ void plat_blocked (edict_t *self, edict_t *other)
// give it a chance to go away on it's own terms (like gibs) // give it a chance to go away on it's own terms (like gibs)
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH); T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it // if it's still there, nuke it
if (other) /* Hack for entity without it's origin near the model */
{ VectorMA (other->absmin, 0.5, other->size, other->s.origin);
/* Hack for entity without it's origin near the model */ BecomeExplosion1(other);
vec3_t save;
VectorCopy(other->s.origin,save);
VectorMA (other->absmin, 0.5, other->size, other->s.origin);
BecomeExplosion1(other);
}
return; return;
} }
@ -1497,15 +1491,9 @@ void door_blocked (edict_t *self, edict_t *other)
// give it a chance to go away on it's own terms (like gibs) // give it a chance to go away on it's own terms (like gibs)
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH); T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it // if it's still there, nuke it
if (other) /* Hack for entitiy without their origin near the model */
{ VectorMA (other->absmin, 0.5, other->size, other->s.origin);
/* Hack for entitiy without their origin near the model */ BecomeExplosion1(other);
vec3_t save;
VectorCopy(other->s.origin,save);
VectorMA (other->absmin, 0.5, other->size, other->s.origin);
BecomeExplosion1(other);
}
return; return;
} }
@ -1928,15 +1916,9 @@ void train_blocked (edict_t *self, edict_t *other)
// give it a chance to go away on it's own terms (like gibs) // give it a chance to go away on it's own terms (like gibs)
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH); T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it // if it's still there, nuke it
if (other) /* Hack for entity without an origin near the model */
{ VectorMA (other->absmin, 0.5, other->size, other->s.origin);
/* Hack for entity without an origin near the model */ BecomeExplosion1(other);
vec3_t save;
VectorCopy(other->s.origin,save);
VectorMA (other->absmin, 0.5, other->size, other->s.origin);
BecomeExplosion1(other);
}
return; return;
} }
@ -2620,15 +2602,9 @@ void door_secret_blocked (edict_t *self, edict_t *other)
// give it a chance to go away on it's own terms (like gibs) // give it a chance to go away on it's own terms (like gibs)
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH); T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it // if it's still there, nuke it
if (other) /* Hack for entities without their origin near the model */
{ VectorMA (other->absmin, 0.5, other->size, other->s.origin);
/* Hack for entities without their origin near the model */ BecomeExplosion1(other);
vec3_t save;
VectorCopy(other->s.origin,save);
VectorMA (other->absmin, 0.5, other->size, other->s.origin);
BecomeExplosion1(other);
}
return; return;
} }

View File

@ -153,11 +153,6 @@ void ThrowGib (edict_t *self, char *gibname, int damage, int type)
vec3_t size; vec3_t size;
float vscale; float vscale;
if (!self)
{
return;
}
if (!self || !gibname) if (!self || !gibname)
{ {
return; return;
@ -334,11 +329,6 @@ void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin)
edict_t *chunk; edict_t *chunk;
vec3_t v; vec3_t v;
if (!self)
{
return;
}
if (!self || !modelname) if (!self || !modelname)
{ {
return; return;

View File

@ -1102,7 +1102,7 @@ void SV_Physics_Step (edict_t *ent)
void SV_Physics_FallFloat (edict_t *ent) void SV_Physics_FallFloat (edict_t *ent)
{ {
float gravVal = ent->gravity * sv_gravity->value * FRAMETIME; float gravVal;
qboolean wasonground = false; qboolean wasonground = false;
qboolean hitsound = false; qboolean hitsound = false;
@ -1111,6 +1111,8 @@ void SV_Physics_FallFloat (edict_t *ent)
return; return;
} }
gravVal = ent->gravity * sv_gravity->value * FRAMETIME;
// check velocity // check velocity
SV_CheckVelocity (ent); SV_CheckVelocity (ent);

View File

@ -311,11 +311,6 @@ void ED_CallSpawn (edict_t *ent)
return; return;
} }
if (!ent)
{
return;
}
if (!ent->classname) if (!ent->classname)
{ {
gi.dprintf ("ED_CallSpawn: NULL classname\n"); gi.dprintf ("ED_CallSpawn: NULL classname\n");
@ -369,7 +364,7 @@ char *ED_NewString (const char *string)
for (i=0 ; i< l ; i++) for (i=0 ; i< l ; i++)
{ {
if (string[i] == '\\' && i < l-1) if ((i < l-1) && (string[i] == '\\'))
{ {
i++; i++;
if (string[i] == 'n') if (string[i] == 'n')

View File

@ -27,16 +27,16 @@ edict_t *G_Find (edict_t *from, int fieldofs, char *match)
{ {
char *s; char *s;
if (!from)
{
return NULL;
}
if (!from) if (!from)
from = g_edicts; from = g_edicts;
else else
from++; from++;
if (!match)
{
return NULL;
}
for ( ; from < &g_edicts[globals.num_edicts] ; from++) for ( ; from < &g_edicts[globals.num_edicts] ; from++)
{ {
if (!from->inuse) if (!from->inuse)
@ -66,15 +66,11 @@ edict_t *findradius (edict_t *from, vec3_t org, float rad)
vec3_t eorg; vec3_t eorg;
int j; int j;
if (!from)
{
return NULL;
}
if (!from) if (!from)
from = g_edicts; from = g_edicts;
else else
from++; from++;
for ( ; from < &g_edicts[globals.num_edicts]; from++) for ( ; from < &g_edicts[globals.num_edicts]; from++)
{ {
if (!from->inuse) if (!from->inuse)

View File

@ -140,7 +140,7 @@ void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
void AngleVectors2(vec3_t value1, vec3_t angles); void AngleVectors2(vec3_t value1, vec3_t angles);
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct cplane_s *plane); int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
float anglemod(float a); float anglemod(float a);
float LerpAngle(float a1, float a2, float frac); float LerpAngle(float a2, float a1, float frac);
#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
(((p)->type < 3) ? \ (((p)->type < 3) ? \

View File

@ -415,13 +415,15 @@ mmove_t zboss_move_pain3 = {FRAME_pain3Start, FRAME_pain3End, zboss_frames_pain3
void zboss_pain (edict_t *self, edict_t *other, float kick, int damage) void zboss_pain (edict_t *self, edict_t *other, float kick, int damage)
{ {
float r; float r;
float hbreak = (self->max_health / 3.0); float hbreak;
if (!self) if (!self)
{ {
return; return;
} }
hbreak = (self->max_health / 3.0);
// set the skin // set the skin
if (self->health < hbreak) if (self->health < hbreak)
{ {
@ -742,8 +744,8 @@ void zboss_reelInGraaple2(edict_t *self)
{ {
vec3_t vec, dir; vec3_t vec, dir;
float length; float length;
edict_t *enemy = self->laser->enemy; edict_t *enemy;
vec3_t hookoffset = {-5, -24, 34}; vec3_t hookoffset;
vec3_t forward, right; vec3_t forward, right;
if (!self) if (!self)
@ -751,6 +753,9 @@ void zboss_reelInGraaple2(edict_t *self)
return; return;
} }
enemy = self->laser->enemy;
hookoffset = {-5, -24, 34};
AngleVectors (self->s.angles, forward, right, NULL); AngleVectors (self->s.angles, forward, right, NULL);
G_ProjectSource(self->s.origin, hookoffset, forward, right, vec); G_ProjectSource(self->s.origin, hookoffset, forward, right, vec);
VectorSubtract (vec, self->laser->s.origin, dir); VectorSubtract (vec, self->laser->s.origin, dir);
@ -1026,14 +1031,14 @@ mmove_t zboss_move_prehook = {FRAME_preHookStart, FRAME_preHookEnd, zboss_frames
void PlasmaballBlastAnim(edict_t *ent) void PlasmaballBlastAnim(edict_t *ent)
{ {
ent->s.frame++;
ent->s.skinnum++;
if (!ent) if (!ent)
{ {
return; return;
} }
ent->s.frame++;
ent->s.skinnum++;
if(ent->s.frame > 1) if(ent->s.frame > 1)
{ {
G_FreeEdict(ent); G_FreeEdict(ent);

View File

@ -439,10 +439,6 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist)
return; return;
} }
//FIXME: how did we get here with no enemy
if (!enemy)
return;
olddir = anglemod( (int)(actor->ideal_yaw/45)*45 ); olddir = anglemod( (int)(actor->ideal_yaw/45)*45 );
turnaround = anglemod(olddir - 180); turnaround = anglemod(olddir - 180);

View File

@ -531,11 +531,11 @@ void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker)
return; return;
} }
if (attacker && attacker != world && attacker != self) if (attacker != world && attacker != self)
{ {
VectorSubtract (attacker->s.origin, self->s.origin, dir); VectorSubtract (attacker->s.origin, self->s.origin, dir);
} }
else if (inflictor && inflictor != world && inflictor != self) else if (inflictor != world && inflictor != self)
{ {
VectorSubtract (inflictor->s.origin, self->s.origin, dir); VectorSubtract (inflictor->s.origin, self->s.origin, dir);
} }

View File

@ -887,14 +887,14 @@ G_SetClientEvent
*/ */
void G_SetClientEvent (edict_t *ent) void G_SetClientEvent (edict_t *ent)
{ {
if (ent->s.event)
return;
if (!ent) if (!ent)
{ {
return; return;
} }
if (ent->s.event)
return;
if ( ent->groundentity && xyspeed > 225) if ( ent->groundentity && xyspeed > 225)
{ {
if ( (int)(current_client->bobtime+bobmove) != bobcycle ) if ( (int)(current_client->bobtime+bobmove) != bobcycle )

View File

@ -304,7 +304,7 @@ extern void AddPointToBounds ( vec3_t v , vec3_t mins , vec3_t maxs ) ;
extern void ClearBounds ( vec3_t mins , vec3_t maxs ) ; extern void ClearBounds ( vec3_t mins , vec3_t maxs ) ;
extern int BoxOnPlaneSide2 ( vec3_t emins , vec3_t emaxs , struct cplane_s * p ) ; extern int BoxOnPlaneSide2 ( vec3_t emins , vec3_t emaxs , struct cplane_s * p ) ;
extern float anglemod ( float a ) ; extern float anglemod ( float a ) ;
extern float LerpAngle ( float a2 , float a1 , float frac ) ; extern float LerpAngle(float a2, float a1, float frac);
extern float Q_fabs ( float f ) ; extern float Q_fabs ( float f ) ;
extern void R_ConcatTransforms ( float in1 [ 3 ] [ 4 ] , float in2 [ 3 ] [ 4 ] , float out [ 3 ] [ 4 ] ) ; extern void R_ConcatTransforms ( float in1 [ 3 ] [ 4 ] , float in2 [ 3 ] [ 4 ] , float out [ 3 ] [ 4 ] ) ;
extern void R_ConcatRotations ( float in1 [ 3 ] [ 3 ] , float in2 [ 3 ] [ 3 ] , float out [ 3 ] [ 3 ] ) ; extern void R_ConcatRotations ( float in1 [ 3 ] [ 3 ] , float in2 [ 3 ] [ 3 ] , float out [ 3 ] [ 3 ] ) ;

View File

@ -1157,7 +1157,7 @@ Info_ValueForKey(char *s, char *key)
o = value[valueindex]; o = value[valueindex];
while (*s != '\\' && *s) while (*s != '\\')
{ {
if (!*s) if (!*s)
{ {
@ -1222,7 +1222,7 @@ Info_RemoveKey(char *s, char *key)
o = value; o = value;
while (*s != '\\' && *s) while (*s != '\\')
{ {
if (!*s) if (!*s)
{ {
@ -1274,6 +1274,11 @@ Info_SetValueForKey(char *s, char *key, char *value)
int c; int c;
int maxsize = MAX_INFO_STRING; int maxsize = MAX_INFO_STRING;
if (!value || !strlen(value))
{
return;
}
if (strstr(key, "\\") || strstr(value, "\\")) if (strstr(key, "\\") || strstr(value, "\\"))
{ {
Com_Printf("Can't use keys or values with a \\\n"); Com_Printf("Can't use keys or values with a \\\n");
@ -1300,11 +1305,6 @@ Info_SetValueForKey(char *s, char *key, char *value)
Info_RemoveKey(s, key); Info_RemoveKey(s, key);
if (!value || !strlen(value))
{
return;
}
Com_sprintf(newi, sizeof(newi), "\\%s\\%s", key, value); Com_sprintf(newi, sizeof(newi), "\\%s\\%s", key, value);
if (strlen(newi) + strlen(s) > maxsize) if (strlen(newi) + strlen(s) > maxsize)

View File

@ -426,13 +426,14 @@ void monster_autocannon_findenemy(edict_t *self)
void monster_autocannon_turn(edict_t *self) void monster_autocannon_turn(edict_t *self)
{ {
vec3_t old_angles; vec3_t old_angles;
VectorCopy(self->s.angles, old_angles);
if (!self) if (!self)
{ {
return; return;
} }
VectorCopy(self->s.angles, old_angles);
if (!self->enemy) if (!self->enemy)
{ {
if (self->monsterinfo.linkcount > 0) if (self->monsterinfo.linkcount > 0)

View File

@ -102,13 +102,15 @@ int zFindRoamYaw(edict_t *self, float distcheck)
{ {
vec3_t forward, end, angles; vec3_t forward, end, angles;
trace_t tr; trace_t tr;
float current = anglemod(self->s.angles[YAW]); float current;
if (!self) if (!self)
{ {
return 0; return 0;
} }
current = anglemod(self->s.angles[YAW]);
if(current <= self->ideal_yaw - 1 || current > self->ideal_yaw + 1) if(current <= self->ideal_yaw - 1 || current > self->ideal_yaw + 1)
{ {
if(fabs(current - self->ideal_yaw) <= 359.0) if(fabs(current - self->ideal_yaw) <= 359.0)