From: PatR Date: Wed, 24 Aug 2016 02:37:42 +0000 (-0700) Subject: fix #H4492 - ing_suffix("throw") gave "throwwing" X-Git-Tag: NetHack-3.6.1_RC01~621 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6fc21bfaa09c09049eced136635347f317cd63ca;p=nethack fix #H4492 - ing_suffix("throw") gave "throwwing" 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. --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 96aba09c7..332e05c63 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -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 diff --git a/src/hacklib.c b/src/hacklib.c index 256ac5743..4d75ba73a 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -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])