From 145ff80ec565e96cc941cb3f8f8a2c308f59ceec Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 4 Nov 2015 02:57:40 -0800 Subject: [PATCH] multishot throwing/shooting feedback While the topic of strprepend() is current, make good use of it. Simplify code which inserts "the Nth " in front of "". I'm pretty sure there are one or two other places where I assumed that the outpuf of xname() was a char array which is BUFSZ in length rather than BUFSZ-PREFIX, and reused the buffer, but I don't know where they occur. (BUFSZ-PREFIX is still big enough to hold most things, so it might not lead to trouble.) --- src/objnam.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index c58a588e2..7eb0531ae 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 objnam.c $NHDT-Date: 1446191877 2015/10/30 07:57:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.150 $ */ +/* NetHack 3.6 objnam.c $NHDT-Date: 1446634657 2015/11/04 10:57:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.151 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -619,13 +619,10 @@ struct obj *obj; char *onm = xname(obj); if (m_shot.n > 1 && m_shot.o == obj->otyp) { - /* copy xname's result so that we can reuse its return buffer */ - Strcpy(tmpbuf, onm); - /* play it safe even though there's no risk of overflowing onm[] */ - tmpbuf[BUFSZ - sizeof "the Nth "] = '\0'; /* "the Nth arrow"; value will eventually be passed to an() or The(), both of which correctly handle this "the " prefix */ - Sprintf(onm, "the %d%s %s", m_shot.i, ordin(m_shot.i), tmpbuf); + Sprintf(tmpbuf, "the %d%s ", m_shot.i, ordin(m_shot.i)); + onm = strprepend(onm, tmpbuf); } return onm; }