Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed possible undefined behaviour #1095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions codemp/game/NPC_reactions.c
Expand Up @@ -220,7 +220,6 @@ NPC_ChoosePainAnimation
extern int G_PickPainAnim( gentity_t *self, vec3_t point, int damage, int hitLoc );
void NPC_ChoosePainAnimation( gentity_t *self, gentity_t *other, vec3_t point, int damage, int mod, int hitLoc, int voiceEvent )
{
int pain_anim = -1;
float pain_chance;

//If we've already taken pain, then don't take it again
Expand Down Expand Up @@ -287,7 +286,7 @@ void NPC_ChoosePainAnimation( gentity_t *self, gentity_t *other, vec3_t point, i
//See if we're going to flinch
if ( Q_flrand(0.0f, 1.0f) < pain_chance )
{
int animLength;
int pain_anim = -1;

//Pick and play our animation
if ( self->client->ps.fd.forceGripBeingGripped < level.time )
Expand Down Expand Up @@ -363,7 +362,13 @@ void NPC_ChoosePainAnimation( gentity_t *self, gentity_t *other, vec3_t point, i
self->painDebounceTime = level.time + 4000;
}
*/
animLength = bgAllAnims[self->localAnimIndex].anims[pain_anim].numFrames * fabs((float)(bgHumanoidAnimations[pain_anim].frameLerp));
int animLength = 0;

if ((self->localAnimIndex >= 0) && (self->localAnimIndex < MAX_ANIM_FILES)
&& (pain_anim >= 0) && (pain_anim < MAX_TOTALANIMATIONS)) {
animLength = bgAllAnims[self->localAnimIndex].anims[pain_anim].numFrames * fabs((float)(bgHumanoidAnimations[pain_anim].frameLerp));
}


self->painDebounceTime = level.time + animLength;
self->client->ps.weaponTime = 0;
Expand Down