diff --git a/include/decl.h b/include/decl.h index b69a9c43d..151eabde7 100644 --- a/include/decl.h +++ b/include/decl.h @@ -1156,6 +1156,7 @@ struct const_globals { extern const struct const_globals cg; extern struct obj hands_obj; +extern char do_random_str; #endif /* DECL_H */ diff --git a/include/extern.h b/include/extern.h index c53de5ebe..8466eb377 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2125,10 +2125,7 @@ extern char *bare_artifactname(struct obj *) NONNULLARG1; that leads to impossible(), preventing NONNULLARG1 */ extern char *makeplural(const char *) NO_NONNULLS; extern char *makesingular(const char *) NO_NONNULLS; -/* readobjnam() allows a NULL to trigger code path for random; if it - and its caller were modifed to look for/provide a particular address - to use as a trigger instead, it could be declared NONNULLARG1 */ -extern struct obj *readobjnam(char *, struct obj *) NO_NONNULLS; +extern struct obj *readobjnam(char *, struct obj *) NONNULLARG1; extern int rnd_class(int, int); /* discover_object() passes NULL arg2 to Japanese_item_name(), * preventing NONNULLARG2 */ diff --git a/src/decl.c b/src/decl.c index 1eb3ece64..4ec2544bf 100644 --- a/src/decl.c +++ b/src/decl.c @@ -1069,8 +1069,10 @@ decl_globals_init(void) gu.urace = urace_init_data; } -/* fields in 'hands_obj' don't matter, just its distinct address */ +/* fields in 'hands_obj' and contents of 'do_random_str' don't matter, + * just their distinct addresses */ struct obj hands_obj = DUMMY; +char do_random_str = '\0'; /* gcc 12.2's static analyzer thinks that some fields of gc.context.victual are uninitialized when compiling 'bite(eat.c)' but that's impossible; diff --git a/src/objnam.c b/src/objnam.c index 71c7a49f8..7b132beca 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -4576,7 +4576,7 @@ readobjnam_postparse3(struct _readobjnam_data *d) /* - * Return something wished for. Specifying a null pointer for + * Return something wished for. Specifying &do_random_str 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 &hands_obj; if an error (no matching object), @@ -4588,7 +4588,7 @@ readobjnam(char *bp, struct obj *no_wish) struct _readobjnam_data d; readobjnam_init(bp, &d); - if (!bp) + if (bp == &do_random_str) goto any; /* first, remove extra whitespace they may have typed */ diff --git a/src/zap.c b/src/zap.c index 83d2dcf62..413ac4c96 100644 --- a/src/zap.c +++ b/src/zap.c @@ -6024,7 +6024,7 @@ makewish(void) if (++tries < MAXWISHTRY) goto retry; pline1(thats_enough_tries); - otmp = readobjnam((char *) 0, (struct obj *) 0); + otmp = readobjnam(&do_random_str, (struct obj *) 0); if (!otmp) return; /* for safety; should never happen */ } else if (otmp == ¬hing) {