github PR #787 - segfault for wizterrain wish

Pull request from entrez:  the change to show the result of a wish in
its gamelog/livelog event resulted in a segfault if that result was
&zeroobj.  It occurs for wizard mode wishes producing terrain changes
instead of objects.

Closes #787
This commit is contained in:
PatR
2022-06-03 12:10:55 -07:00
+5 -6
View File
@@ -5674,6 +5674,9 @@ makewish(void)
to retain wishless conduct */ to retain wishless conduct */
livelog_printf(LL_WISH, "declined to make a wish"); livelog_printf(LL_WISH, "declined to make a wish");
return; return;
} else if (otmp == &cg.zeroobj) {
/* wizard mode terrain wish: skip livelogging, etc */
return;
} }
if (otmp->oartifact) { if (otmp->oartifact) {
@@ -5696,9 +5699,7 @@ makewish(void)
/* TODO? maybe generate a second event decribing what was received since /* TODO? maybe generate a second event decribing what was received since
those just echo player's request rather than show actual result */ those just echo player's request rather than show actual result */
if (otmp != &cg.zeroobj) { const char *verb = ((Is_airlevel(&u.uz) || u.uinwater) ? "slip" : "drop"),
const char
*verb = ((Is_airlevel(&u.uz) || u.uinwater) ? "slip" : "drop"),
*oops_msg = (u.uswallow *oops_msg = (u.uswallow
? "Oops! %s out of your reach!" ? "Oops! %s out of your reach!"
: (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)
@@ -5708,11 +5709,9 @@ makewish(void)
: "Oops! %s to the floor!"); : "Oops! %s to the floor!");
/* The(aobjnam()) is safe since otmp is unidentified -dlc */ /* The(aobjnam()) is safe since otmp is unidentified -dlc */
(void) hold_another_object(otmp, oops_msg, (void) hold_another_object(otmp, oops_msg, The(aobjnam(otmp, verb)),
The(aobjnam(otmp, verb)),
(const char *) 0); (const char *) 0);
u.ublesscnt += rn1(100, 50); /* the gods take notice */ u.ublesscnt += rn1(100, 50); /* the gods take notice */
}
} }
/* Fills buf with the appropriate string for this ray. /* Fills buf with the appropriate string for this ray.