diff --git a/include/extern.h b/include/extern.h index 548290712..995f99b93 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1484,7 +1484,8 @@ E int NDECL(doloot); E int FDECL(use_container, (struct obj *,int)); E int FDECL(loot_mon, (struct monst *,int *,boolean *)); E int NDECL(dotip); -E char *FDECL(safe_qbuf, (char *,unsigned,char *,char *,char *)); +E const char *FDECL(safe_qbuf, (const char *,unsigned, + const char *,const char *,const char *)); /* ### pline.c ### */ diff --git a/src/apply.c b/src/apply.c index 36d6bbf58..7288961a8 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2025,7 +2025,6 @@ struct obj *otmp; should be incorporated here instead of in set_trap]*/ #ifdef STEED if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { - char buf[BUFSZ]; boolean chance; if (Fumbling || otmp->cursed) chance = (rnl(10) > 3); diff --git a/src/pickup.c b/src/pickup.c index 1daf7b129..5664cb11b 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1154,19 +1154,25 @@ boolean telekinesis; * finally using the fallback as a last resort. * last_restort is expected to be very short. */ -char * +const char * safe_qbuf(qbuf, padlength, planA, planB, last_resort) -char *qbuf, *planA, *planB, *last_resort; +const char *qbuf, *planA, *planB, *last_resort; unsigned padlength; { - unsigned textleft = QBUFSZ - (strlen(qbuf) + padlength); - if (strlen(last_resort) >= textleft) { - impossible("safe_qbuf: last_resort too large at %d characters.", - strlen(last_resort)); - return ""; + /* convert size_t (or int for ancient systems) to ordinary unsigned */ + unsigned len_qbuf = (unsigned)strlen(qbuf), + len_planA = (unsigned)strlen(planA), + len_planB = (unsigned)strlen(planB), + len_lastR = (unsigned)strlen(last_resort); + unsigned textleft = QBUFSZ - (len_qbuf + padlength); + + if (len_lastR >= textleft) { + impossible("safe_qbuf: last_resort too large at %u characters.", + len_lastR); + return ""; } - return (strlen(planA) < textleft) ? planA : - (strlen(planB) < textleft) ? planB : last_resort; + return (len_planA < textleft) ? planA : + (len_planB < textleft) ? planB : last_resort; } /* diff --git a/src/trap.c b/src/trap.c index 7cc2cd78f..379640fb5 100644 --- a/src/trap.c +++ b/src/trap.c @@ -2803,6 +2803,7 @@ drown() } #endif crawl_ok = FALSE; + x = y = 0; /* lint suppression */ /* if sleeping, wake up now so that we don't crawl out of water while still asleep; we can't do that the same way that waking due to combat is handled; note unmul() clears u.usleep */