Skip to content

Commit

Permalink
Fix: prevent segfault for non-existent trap.
Browse files Browse the repository at this point in the history
Caught this while fuzzing. Fix comes from NetHack 3.7 commit 5615974,
slightly modified plus some other improvements in this block of code.
  • Loading branch information
k21971 committed Mar 12, 2025
1 parent 4b0dd73 commit 27a4d7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/evilhack-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4383,4 +4383,5 @@ The following changes to date are:
'output' used (windows build, crafting traps)
- Debug hints files tweak
- Fix: get rid of unneeded dispose_of_orig_obj() call
- Fix: prevent segfault for non-existent trap

12 changes: 8 additions & 4 deletions src/do.c
Original file line number Diff line number Diff line change
Expand Up @@ -2306,12 +2306,16 @@ struct obj *corpse;
struct trap *ttmp;

ttmp = t_at(mtmp->mx, mtmp->my);
ttmp->tseen = TRUE;
if (ttmp)
ttmp->tseen = TRUE;
pline("%s claws its way out of the ground!",
Amonnam(mtmp));
canspotmon(mtmp) ? Amonnam(mtmp) : Something);
newsym(mtmp->mx, mtmp->my);
} else if (distu(mtmp->mx, mtmp->my) < 5 * 5)
You_hear("scratching noises.");
} else if (distu(mtmp->mx, mtmp->my) < 5 * 5) {
if (!Deaf)
You_hear("scratching noises.");
}
fill_pit(mtmp->mx, mtmp->my);
break;
}
/*FALLTHRU*/
Expand Down

0 comments on commit 27a4d7f

Please sign in to comment.