From: nethack.rankin Date: Sat, 31 May 2003 07:14:21 +0000 (+0000) Subject: some lint cleanup X-Git-Tag: MOVE2GIT~1946 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=678e05096de398704a88cb64f973bd2259e101be;p=nethack some lint cleanup Mostly `gcc -Wwrite-strings' complaining about passing string literals to safe_qbuf(). `gcc -Wformat' didn't catch the type mismatch of formatting the return value of strlen() with %d, presumeably because size_t is defined as unsigned int on this system and it treats int and unsigned int as interchangeable as far as printf/scanf checking goes. I'm not sure whether the sizeof() values being passed to safe_qbuf() ought to have casts. Any system where size_t isn't the same width as unsigned int is bound to support prototypes, but might possibly warn about the implicit conversion of unsigned long (or even unsigned long long these days) to unsigned int. --- 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 ""; - } - return (strlen(planA) < textleft) ? planA : - (strlen(planB) < textleft) ? planB : last_resort; + /* 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 (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 */