fix #H7702 - named fruit warning: singular of null

Some code added for 3.6.1 tries to find the longest matching prefix
when comparing a user-supplied with previously set up fruit names.
It does so by temporarily replacing space with NUL then passing that
to makesingular().  After already having named a fruit (resulting in
something to try to compare with), attempting to assign a name
beginning with two or more spaces would yield an impossible "singular
of null?" warning.

After the warning, the name minus its leading spaces got successfully
assigned.  I'm not sure why a single leading space didn't trigger it
too, nor where the leading (and trailing, if any) spaces are going
away when the name is assigned.

Fix by removing all leading and trailing spaces from a new fruit name,
and combine consecutive internal spaces to one, before any other
manipulations.  (This can result in names that used to work as-is now
being simplified a bit--when consecutive internal spaces have been
given--but that shouldn't be a problem.)

Also, don't complain about "missing parameter for 'fruit:'" if user
hits <return> when prompted for fruit name by 'O'.  An empty fruit
name at that stage is just a no-op.
This commit is contained in:
PatR
2018-12-09 15:03:13 -08:00
parent d93b8b50ae
commit fe1b27e774
2 changed files with 16 additions and 9 deletions

View File

@@ -252,12 +252,14 @@ hero hit by something that causes inventory items to be destroyed with loss of
similar problem with more obvious symptom, an "object lost" panic when
the unholy water was wielded; the fix for that wasn't general enough]
add MM_ASLEEP makemon() flag and honor it when creating group for fill_zoo
at start of session (new game or restore), HILITE_STATUS for gold was ignored
if player creates any menu colors via 'O' while menucolors is off, issue a
reminder that it needs to be on in order for those to become effective
add MM_NOGRP makemon() flag as a means of suppressing groups of monsters in
a couple places that warrant it when a specific monster type isn't
specified on the call to makemon()
at start of session (new game or restore), HILITE_STATUS for gold was ignored
if player creates any menu colors via 'O' while menucolors is off, issue a
reminder that it needs to be on in order for those to become effective
setting second or later named fruit to value beginning with two or more spaces
followed by non-space gave "singular of null?" warning
Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 options.c $NHDT-Date: 1544174413 2018/12/07 09:20:13 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.339 $ */
/* NetHack 3.6 options.c $NHDT-Date: 1544396581 2018/12/09 23:03:01 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.340 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2008. */
/* NetHack may be freely redistributed. See license for details. */
@@ -883,6 +883,8 @@ initoptions_finish()
return;
}
/* copy up to maxlen-1 characters; 'dest' must be able to hold maxlen;
treat comma as alternate end of 'src' */
STATIC_OVL void
nmcpy(dest, src, maxlen)
char *dest;
@@ -896,7 +898,7 @@ int maxlen;
break; /*exit on \0 terminator*/
*dest++ = *src++;
}
*dest = 0;
*dest = '\0';
}
/*
@@ -2583,7 +2585,7 @@ boolean tinitial, tfrom_file;
if (duplicate)
complain_about_duplicate(opts, 1);
op = string_for_opt(opts, negated);
op = string_for_opt(opts, negated || !initial);
if (negated) {
if (op) {
bad_negation("fruit", TRUE);
@@ -2594,6 +2596,8 @@ boolean tinitial, tfrom_file;
}
if (!op)
return FALSE;
/* 3.6.2: strip leading and trailing spaces, condense internal ones */
mungspaces(op);
if (!initial) {
struct fruit *f;
int fnum = 0;
@@ -4465,7 +4469,7 @@ doset() /* changing options via menu by Per Liboriussen */
/* boolean option */
Sprintf(buf, "%s%s", *boolopt[opt_indx].addr ? "!" : "",
boolopt[opt_indx].name);
parseoptions(buf, setinitial, fromfile);
(void) parseoptions(buf, setinitial, fromfile);
if (wc_supported(boolopt[opt_indx].name)
|| wc2_supported(boolopt[opt_indx].name))
preference_update(boolopt[opt_indx].name);
@@ -4481,7 +4485,7 @@ doset() /* changing options via menu by Per Liboriussen */
continue;
Sprintf(buf, "%s:%s", compopt[opt_indx].name, buf2);
/* pass the buck */
parseoptions(buf, setinitial, fromfile);
(void) parseoptions(buf, setinitial, fromfile);
}
if (wc_supported(compopt[opt_indx].name)
|| wc2_supported(compopt[opt_indx].name))
@@ -4639,7 +4643,8 @@ boolean setinitial, setfromfile;
destroy_nhwindow(tmpwin);
} else if (!strcmp("pickup_types", optname)) {
/* parseoptions will prompt for the list of types */
parseoptions(strcpy(buf, "pickup_types"), setinitial, setfromfile);
(void) parseoptions(strcpy(buf, "pickup_types"),
setinitial, setfromfile);
} else if (!strcmp("disclose", optname)) {
/* order of disclose_names[] must correspond to
disclosure_options in decl.c */