From: PatR Date: Fri, 18 Dec 2015 09:59:36 +0000 (-0800) Subject: suppression of while-helpless for tombstone X-Git-Tag: NetHack-3.6.1_RC01~1157 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4604777c168d4ef5415aec062b99d1f48cdfe9be;p=nethack suppression of while-helpless for tombstone 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 called " being displayed on the tombstone after stripping while-helpless reason to shorten the text. --- diff --git a/include/extern.h b/include/extern.h index 3806f5be6..564d863fd 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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 *)); diff --git a/src/bones.c b/src/bones.c index 423d3e3d0..6784259c6 100644 --- a/src/bones.c +++ b/src/bones.c @@ -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; diff --git a/src/dungeon.c b/src/dungeon.c index 96b99591d..d101651a0 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -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"); diff --git a/src/end.c b/src/end.c index 20ca00d09..5e5231856 100644 --- 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 */ diff --git a/src/rip.c b/src/rip.c index c20cce2e2..64bd8dd01 100644 --- 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++) { diff --git a/src/topten.c b/src/topten.c index 553332352..22ebaae1f 100644 --- a/src/topten.c +++ b/src/topten.c @@ -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;