use gi.invalid_obj instead of cg.zeroobj

cg.zeroobj was originally added (under its previous unprefixed name)
for providing a one-line way to zero out the fields of a struct obj.

    struct obj tempobj;
    tempobj = cg.zeroobj;

    initfn(struct obj *otmp)
    {
        if (otmp)
            *otmp = cg.zeroobj;
    }

More recently, the address of cg.zeroobj began to be used as a return
flag to indicate some things, but the 'const struct obj zeroobj' wasn't
an ideal fit for the purpose and required a number of casts, including
casting away const.

Provide a better fitting variable (gi.invalid_obj) and eliminate a
number of casts.
This commit is contained in:
nhmall
2023-11-10 11:07:49 -05:00
parent 17dd51d922
commit 314a2a9489
14 changed files with 35 additions and 30 deletions

View File

@@ -3266,7 +3266,7 @@ wizterrainwish(struct _readobjnam_data *d)
(trap != MAGIC_PORTAL) ? "" : " to nowhere");
} else
pline("Creation of %s failed.", an(tname));
return (struct obj *) &cg.zeroobj;
return &gi.invalid_obj;
}
/* furniture and terrain (use at your own risk; can clobber stairs
@@ -3540,7 +3540,7 @@ wizterrainwish(struct _readobjnam_data *d)
}
if (madeterrain || badterrain) {
/* cast 'const' away; caller won't modify this */
return (struct obj *) &cg.zeroobj;
return &gi.invalid_obj;
}
return (struct obj *) 0;
@@ -4495,7 +4495,7 @@ readobjnam_postparse3(struct _readobjnam_data *d)
* Return something wished for. Specifying a null pointer for
* the user request string results in a random object. Otherwise,
* if asking explicitly for "nothing" (or "nil") return no_wish;
* if not an object return &cg.zeroobj; if an error (no matching object),
* if not an object return &gi.invalid_obj; if an error (no matching object),
* return null.
*/
struct obj *
@@ -4960,7 +4960,7 @@ readobjnam(char *bp, struct obj *no_wish)
|| (d.otmp->oartifact && rn2(nartifact_exist()) > 1)) && !wizard) {
artifact_exists(d.otmp, safe_oname(d.otmp), FALSE, ONAME_NO_FLAGS);
obfree(d.otmp, (struct obj *) 0);
d.otmp = (struct obj *) &cg.zeroobj;
d.otmp = (struct obj *) &gi.invalid_obj;
pline("For a moment, you feel %s in your %s, but it disappears!",
something, makeplural(body_part(HAND)));
return d.otmp;