From 10498b15352b81a174ca47ff8a23706e71db0977 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 12 Oct 2024 11:09:50 -0700 Subject: [PATCH] monster swapping armor simplification Slightly simplify yesterday's message adjustment made when a monster takes off a piece of armor and puts on a different instance of the same type of armor. ("a|an " -> "another ") --- src/worn.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/worn.c b/src/worn.c index 473765764..aae1611a4 100644 --- a/src/worn.c +++ b/src/worn.c @@ -847,7 +847,7 @@ m_dowear_type( if (!creation) { if (sawmon) { - char buf[BUFSZ], oldarm[BUFSZ], newarm[BUFSZ]; + char buf[BUFSZ], oldarm[BUFSZ], newarm[BUFSZ + sizeof "another "]; /* " [removes and ]puts on ." uses accessory verbs for armor but we can live with that */ @@ -863,14 +863,13 @@ m_dowear_type( if newarm and oldarm have identical descriptions, substitute "another " for "a|an " */ if (!strcmpi(newarm, oldarm)) { - if (!strncmpi(newarm, "a ", 2) - && strlen(newarm) + sizeof "another " - sizeof "a " - < sizeof newarm) + /* size of newarm[] has been overallocated to guarantee + enough room to insert "another " */ + if (!strncmpi(newarm, "a ", 2)) (void) strsubst(newarm, "a ", "another "); - else if (!strncmpi(newarm, "an ", 3) - && strlen(newarm) + sizeof "another " - sizeof "an " - < sizeof newarm) + else if (!strncmpi(newarm, "an ", 3)) (void) strsubst(newarm, "an ", "another "); + newarm[BUFSZ - 1] = '\0'; } pline("%s%s puts on %s.", Monnam(mon), buf, newarm); if (autocurse)