]> granicus.if.org Git - nethack/commitdiff
some lint cleanup
authornethack.rankin <nethack.rankin>
Sat, 31 May 2003 07:14:21 +0000 (07:14 +0000)
committernethack.rankin <nethack.rankin>
Sat, 31 May 2003 07:14:21 +0000 (07:14 +0000)
     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.

include/extern.h
src/apply.c
src/pickup.c
src/trap.c

index 548290712f84aa2e089607959c2ede64433647f5..995f99b93dc88c436fe81c83863e7ba2422e0cf8 100644 (file)
@@ -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 ### */
 
index 36d6bbf58672cd9f497d920a38437aaf44e9d684..7288961a84905bb57070738d6c000907a2125bc2 100644 (file)
@@ -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);
index 1daf7b129b2f3c554a1e7ea129b65a10f46658a6..5664cb11b92795402d13524fe9004678f41442de 100644 (file)
@@ -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;
 }
 
 /*
index 7cc2cd78f5247711d728be4a15680c86975e91d6..379640fb5d7750fd0add8e631d8a7676f3fe920c 100644 (file)
@@ -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 */