]> granicus.if.org Git - nethack/commitdiff
multishot throwing/shooting feedback
authorPatR <rankin@nethack.org>
Wed, 4 Nov 2015 10:57:40 +0000 (02:57 -0800)
committerPatR <rankin@nethack.org>
Wed, 4 Nov 2015 10:57:40 +0000 (02:57 -0800)
While the topic of strprepend() is current, make good use of it.
Simplify code which inserts "the Nth " in front of "<arrow,&c>".

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

index c58a588e2e929fc0b182620ccaab180edf38b510..7eb0531ae81566f630466f9b71be24c0a0f7a7b9 100644 (file)
@@ -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;
 }