]> granicus.if.org Git - nethack/commitdiff
fix #H4492 - ing_suffix("throw") gave "throwwing"
authorPatR <rankin@nethack.org>
Wed, 24 Aug 2016 02:37:42 +0000 (19:37 -0700)
committerPatR <rankin@nethack.org>
Wed, 24 Aug 2016 02:37:42 +0000 (19:37 -0700)
The bug report assumed "you mime throwwing something" feedback
from 't-' was a typo, but 'throwwing' gets generated from 'throw'.
Change ing_suffix() not to double final 'w'.  Presumeably 'w' and 'y'
are exceptions because they're sometimes used as vowels.

Change 'strrchr()' to 'rindex()' like the rest of nethack.  Someday
those will need to be switched the other way around.

Add some missing bounds checking, although since ing_suffix() isn't
used for user-supplied strings, that's probably superfluous.

doc/fixes36.1
src/hacklib.c

index 96aba09c791046461ef28a7ae1d793a140e72034..332e05c6328615f30834d7ccf8252ff7f8ff4c2d 100644 (file)
@@ -334,6 +334,8 @@ any item drained of enchantment was blamed on the player as far as shop
 if user supplied a specific monster name when asked to choose a monster class,
        first prefix match was picked rather than best match ("titan" yielded
        S_quadruped due to being preceded by "titanothere" in mons[])
+change ing_suffix() to not double final 'w' when adding 'ing' ('t=' yielded
+       "You mime throwwing something.")
 
 
 Fixes to Post-3.6.0 Problems that Were Exposed Via git Repository
index 256ac57437b3ba527f9c866bbba1277eb70c5b32..4d75ba73a33aa007ceb7d3c26c0c2fbfe6e8e7c5 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 hacklib.c       $NHDT-Date: 1450178551 2015/12/15 11:22:31 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.46 $ */
+/* NetHack 3.6 hacklib.c       $NHDT-Date: 1472006251 2016/08/24 02:37:31 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.48 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* Copyright (c) Robert Patrick Rankin, 1991                      */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -297,7 +297,7 @@ char *
 ing_suffix(s)
 const char *s;
 {
-    const char *vowel = "aeiouy";
+    static const char vowel[] = "aeiouwy";
     static char buf[BUFSZ];
     char onoff[10];
     char *p;
@@ -305,21 +305,22 @@ const char *s;
     Strcpy(buf, s);
     p = eos(buf);
     onoff[0] = *p = *(p + 1) = '\0';
-    if ((strlen(buf) > 4)
-        && (!strcmpi(p - 3, " on") || !strcmpi(p - 4, " off")
-            || !strcmpi(p - 5, " with"))) {
-        p = strrchr(buf, ' ');
+    if ((p >= &buf[3] && !strcmpi(p - 3, " on"))
+        || (p >= &buf[4] && !strcmpi(p - 4, " off"))
+        || (p >= &buf[5] && !strcmpi(p - 5, " with"))) {
+        p = rindex(buf, ' ');
         Strcpy(onoff, p);
+        *p = '\0';
     }
-    if (!index(vowel, *(p - 1)) && index(vowel, *(p - 2))
-        && !index(vowel, *(p - 3))) {
+    if (p >= &buf[3] && !index(vowel, *(p - 1))
+        && index(vowel, *(p - 2)) && !index(vowel, *(p - 3))) {
         /* tip -> tipp + ing */
         *p = *(p - 1);
         *(p + 1) = '\0';
-    } else if (!strcmpi(p - 2, "ie")) { /* vie -> vy + ing */
+    } else if (p >= &buf[2] && !strcmpi(p - 2, "ie")) { /* vie -> vy + ing */
         *(p - 2) = 'y';
         *(p - 1) = '\0';
-    } else if (*(p - 1) == 'e') /* grease -> greas + ing */
+    } else if (p >= &buf[1] && *(p - 1) == 'e') /* grease -> greas + ing */
         *(p - 1) = '\0';
     Strcat(buf, "ing");
     if (onoff[0])