]> granicus.if.org Git - nethack/commitdiff
fix #H7702 - named fruit warning: singular of null
authorPatR <rankin@nethack.org>
Sun, 9 Dec 2018 23:03:13 +0000 (15:03 -0800)
committerPatR <rankin@nethack.org>
Sun, 9 Dec 2018 23:03:13 +0000 (15:03 -0800)
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.

doc/fixes36.2
src/options.c

index ac5e5af8765f1327e7fe4c363ffe4b9a5f13300e..7cd1f75f120bf351e3c8c15ec4f8aa4a354b5bf4 100644 (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
index b3595a6add63fd8fa4a132e6f4f6d13e924ae9bf..1bf7f702475715a2e35c11564aa6bff43a04ec5b 100644 (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 */