From 02942e9544489026b13863f9031089be9e82fb1b Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Thu, 7 Sep 2017 18:11:10 +0200 Subject: [PATCH] Fix a potential crash in ai_run_melee() and ai_run_missile(). This was found and fixed by Maraakate. --- src/g_ai.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/g_ai.c b/src/g_ai.c index cf3ef42..e9314f6 100644 --- a/src/g_ai.c +++ b/src/g_ai.c @@ -1046,8 +1046,11 @@ ai_run_melee(edict_t *self) if (FacingIdeal(self)) { - self->monsterinfo.melee(self); - self->monsterinfo.attack_state = AS_STRAIGHT; + if (self->monsterinfo.melee) + { + self->monsterinfo.melee(self); + self->monsterinfo.attack_state = AS_STRAIGHT; + } } } @@ -1072,12 +1075,14 @@ ai_run_missile(edict_t *self) if (FacingIdeal(self)) { - self->monsterinfo.attack(self); - - if ((self->monsterinfo.attack_state == AS_MISSILE) || - (self->monsterinfo.attack_state == AS_BLIND)) + if (self->monsterinfo.attack) { - self->monsterinfo.attack_state = AS_STRAIGHT; + self->monsterinfo.attack(self); + + if ((self->monsterinfo.attack_state == AS_MISSILE) || + (self->monsterinfo.attack_state == AS_BLIND)) { + self->monsterinfo.attack_state = AS_STRAIGHT; + } } } } @@ -1115,7 +1120,7 @@ ai_run_slide(edict_t *self, float distance) } /* clamp maximum sideways move for non flyers to make them look less jerky */ - if (!self->flags & FL_FLY) + if (!(self->flags & FL_FLY)) { distance = min(distance, 0.8); }