Skip to content

Commit

Permalink
Fix: Cleaver's should_cleave could check off map
Browse files Browse the repository at this point in the history
It is possible for the player to hit a monster with Cleaver such that
spaces in the arc are not on the map. The should_cleave function didn't
take this into account, so it was possible to segfault by looking for a
monster there. Add an isok() check to prevent that.

Thanks to paxed for pointing out the bug and qt for finding a reliable
way to make it segfault.
  • Loading branch information
copperwater committed Sep 2, 2021
1 parent d39bfae commit 4da386b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/uhitm.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,12 @@ should_cleave(void)
* trigger this prompt */
for (i = dir + 1; i <= dir + 7; i += 6) {
int realdir = i % 8;
struct monst *mtmp = m_at(u.ux + xdir[realdir], u.uy + ydir[realdir]);
int x = u.ux + xdir[realdir];
int y = u.uy + ydir[realdir];
struct monst *mtmp;
if (!isok(x, y))
continue;
mtmp = m_at(x, y);
if (mtmp && canspotmon(mtmp) && mtmp->mpeaceful) {
bystanders = TRUE;
}
Expand Down

0 comments on commit 4da386b

Please sign in to comment.