Skip to content

Commit 0d722e3

Browse files
committed
Fix: drop_throw assumed breakobj unconditionally breaks an object
This looks like an omission from post-merge commit 8bb473b. The code here is specific to xNetHack, having been added fairly early as part of the object materials system, and was intended to break non-shatterproof glass missiles to balance their generally superior damage. However, this code assumed that breakobj would completely delete the object, an assumption which is no longer true. This caused a fuzzer crash when breakobj did NOT delete the object, and gt.thrownobj remained set to it without being cleared. The fix is to check the return of breakobj and only return early when the object has in fact been deleted. Otherwise, fall through to the standard missile-fall handling (which includes the regular chance of glass ammo, like any ammo, mulching and vanishing without a message).
1 parent 5285008 commit 0d722e3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mthrowu.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ drop_throw(
185185
/* glass and other fragile objects */
186186
if (!IS_SOFT(levl[x][y].typ) && breaktest(obj)) {
187187
breakmsg(obj, cansee(x, y));
188-
breakobj(obj, x, y, FALSE, FALSE);
189-
return TRUE; /* it's already deleted */
188+
if (breakobj(obj, x, y, FALSE, FALSE))
189+
/* object was already deleted; return early */
190+
return TRUE;
191+
/* if breakobj returned 0 (e.g. glass cracked but didn't fully shatter),
192+
* don't set broken to FALSE even so. if it did, glass ammo would
193+
* weirdly be exempt from mulching. */
190194
}
191195
if (broken) {
192196
delobj(obj);

0 commit comments

Comments
 (0)