]> granicus.if.org Git - nethack/commitdiff
suppression of while-helpless for tombstone
authorPatR <rankin@nethack.org>
Fri, 18 Dec 2015 09:59:36 +0000 (01:59 -0800)
committerPatR <rankin@nethack.org>
Fri, 18 Dec 2015 09:59:36 +0000 (01:59 -0800)
Avoid the possibility of a user-supplied name interfering with killer
reason truncation.  A monster named ", while" that killed the hero
would result in "killed by <mon-type> called " being displayed on the
tombstone after stripping while-helpless reason to shorten the text.

include/extern.h
src/bones.c
src/dungeon.c
src/end.c
src/rip.c
src/topten.c

index 3806f5be6a50b10834d90fdc32129e25de5a9676..564d863fd96f0a09802c2f7a2ea4c3b94492ae0c 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 extern.h        $NHDT-Date: 1449051498 2015/12/02 10:18:18 $  $NHDT-Branch: master $:$NHDT-Revision: 1.520 $ */
+/* NetHack 3.6 extern.h        $NHDT-Date: 1450432755 2015/12/18 09:59:15 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.521 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2293,7 +2293,7 @@ E void NDECL(timer_sanity_check);
 
 /* ### topten.c ### */
 
-E void FDECL(formatkiller, (char *, unsigned, int));
+E void FDECL(formatkiller, (char *, unsigned, int, BOOLEAN_P));
 E void FDECL(topten, (int, time_t));
 E void FDECL(prscore, (int, char **));
 E struct obj *FDECL(tt_oname, (struct obj *));
index 423d3e3d08c93d9c459fdd93eddba3ecd51efa18..6784259c65e74019f67cc52a15028440891cef27 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 bones.c $NHDT-Date: 1450261363 2015/12/16 10:22:43 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.67 $ */
+/* NetHack 3.6 bones.c $NHDT-Date: 1450432756 2015/12/18 09:59:16 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.68 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -479,7 +479,7 @@ make_bones:
     Sprintf(newbones->who, "%s-%.3s-%.3s-%.3s-%.3s", plname, urole.filecode,
             urace.filecode, genders[flags.female].filecode,
             aligns[1 - u.ualign.type].filecode);
-    formatkiller(newbones->how, sizeof newbones->how, how);
+    formatkiller(newbones->how, sizeof newbones->how, how, TRUE);
     Strcpy(newbones->when, yyyymmddhhmmss(when));
     /* final resting place, used to decide when bones are discovered */
     newbones->frpx = u.ux, newbones->frpy = u.uy;
index 96b99591d08565b69fac0a347b3254d5a8e8276b..d101651a058ec55880fe8aae26aba0ebab86dffe 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 dungeon.c       $NHDT-Date: 1448862377 2015/11/30 05:46:17 $  $NHDT-Branch: master $:$NHDT-Revision: 1.69 $ */
+/* NetHack 3.6 dungeon.c       $NHDT-Date: 1450432757 2015/12/18 09:59:17 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.70 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2895,7 +2895,7 @@ boolean printdun;
             if (died_here) {
                 /* disclosure occurs before bones creation, so listing dead
                    hero here doesn't give away whether bones are produced */
-                formatkiller(tmpbuf, sizeof tmpbuf, how);
+                formatkiller(tmpbuf, sizeof tmpbuf, how, TRUE);
                 /* rephrase a few death reasons to work with "you" */
                 (void) strsubst(tmpbuf, " himself", " yourself");
                 (void) strsubst(tmpbuf, " herself", " yourself");
index 20ca00d098b11d66d9572121383c2bc3130a6003..5e52318562c8ce14bf157c32c758059ceba227d0 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 end.c   $NHDT-Date: 1450231174 2015/12/16 01:59:34 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.110 $ */
+/* NetHack 3.6 end.c   $NHDT-Date: 1450432758 2015/12/18 09:59:18 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.111 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1039,7 +1039,7 @@ int how;
         }
         corpse = mk_named_object(CORPSE, &mons[mnum], u.ux, u.uy, plname);
         Sprintf(pbuf, "%s, ", plname);
-        formatkiller(eos(pbuf), sizeof pbuf - strlen(pbuf), how);
+        formatkiller(eos(pbuf), sizeof pbuf - strlen(pbuf), how, TRUE);
         make_grave(u.ux, u.uy, pbuf);
     }
     pbuf[0] = '\0'; /* clear grave text; also lint suppression */
index c20cce2e23cc9930071ea6957fb9e68761c1021a..64bd8dd01842ac072dd6024ce9a8a3a55c2b6fac 100644 (file)
--- a/src/rip.c
+++ b/src/rip.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 rip.c   $NHDT-Date: 1450410547 2015/12/18 03:49:07 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.21 $ */
+/* NetHack 3.6 rip.c   $NHDT-Date: 1450432760 2015/12/18 09:59:20 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.22 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -91,7 +91,7 @@ time_t when;
 {
     register char **dp;
     register char *dpx;
-    char buf[BUFSZ], *p;
+    char buf[BUFSZ];
     long year;
     register int x;
     int line;
@@ -112,10 +112,7 @@ time_t when;
     center(GOLD_LINE, buf);
 
     /* Put together death description */
-    formatkiller(buf, sizeof buf, how);
-    /* strip ", while helpless" to keep reason shorter */
-    if ((p = strstr(buf, ", while")) != 0)
-        *p = '\0';
+    formatkiller(buf, sizeof buf, how, FALSE);
 
     /* Put death type on stone */
     for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) {
index 553332352100b5433515b7f3bf93db116855a762..22ebaae1f4348df22c90213452de250692b662d1 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 topten.c        $NHDT-Date: 1450410548 2015/12/18 03:49:08 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.42 $ */
+/* NetHack 3.6 topten.c        $NHDT-Date: 1450432761 2015/12/18 09:59:21 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.43 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -84,10 +84,11 @@ static winid toptenwin = WIN_ERR;
 
 /* "killed by",&c ["an"] 'killer.name' */
 void
-formatkiller(buf, siz, how)
+formatkiller(buf, siz, how, incl_helpless)
 char *buf;
 unsigned siz;
 int how;
+boolean incl_helpless;
 {
     static NEARDATA const char *const killed_by_prefix[] = {
         /* DIED, CHOKING, POISONING, STARVING, */
@@ -122,12 +123,13 @@ int how;
        appending, but strncat() appends a terminator and strncpy() doesn't */
     (void) strncat(buf, kname, siz - 1);
 
-    if (multi) {
+    if (incl_helpless && multi) {
         siz -= strlen(buf);
         buf = eos(buf);
         /* X <= siz: 'sizeof "string"' includes 1 for '\0' terminator */
         if (multi_reason && strlen(multi_reason) + sizeof ", while " <= siz)
             Sprintf(buf, ", while %s", multi_reason);
+        /* either multi_reason wasn't specified or wouldn't fit */
         else if (sizeof ", while helpless" <= siz)
             Strcpy(buf, ", while helpless");
         /* else extra death info won't fit, so leave it out */
@@ -542,7 +544,7 @@ time_t when;
     copynchars(t0->plgend, genders[flags.female].filecode, ROLESZ);
     copynchars(t0->plalign, aligns[1 - u.ualign.type].filecode, ROLESZ);
     copynchars(t0->name, plname, NAMSZ);
-    formatkiller(t0->death, sizeof t0->death, how);
+    formatkiller(t0->death, sizeof t0->death, how, TRUE);
     t0->birthdate = yyyymmdd(ubirthday);
     t0->deathdate = yyyymmdd(when);
     t0->tt_next = 0;