Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site mcvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!mcvax!aeb From: aeb@mcvax.UUCP (Andries Brouwer) Newsgroups: net.lang.c Subject: How to let lint check your format strings Message-ID: <558@mcvax.UUCP> Date: Sat, 30-Mar-85 20:24:11 EST Article-I.D.: mcvax.558 Posted: Sat Mar 30 20:24:11 1985 Date-Received: Sat, 6-Apr-85 01:43:01 EST Reply-To: aeb@mcvax.UUCP (Andries Brouwer) Organization: CWI, Amsterdam Lines: 36 In order to enable lint to check the correspondence between the format specifications of printf-like functions (like %d, %ld, %s) and the number and type of actual arguments one might do the following. Replace each call sprintf(buf, "A %20s%*d", s, m, n); by sprintf(buf, "A %20s%*d", procent_s(s), procent_d(m), procent_d(n)); The routines procent.. are declared in a file procent.c with a content like int procent_d(d) int d; { return(d); } long procent_D(D) long D; { return(D); } unsigned long procent_U(U) unsigned long U; { return(U); } char procent_c(c) char c; { return(c); } char *procent_s(s) char *s; { return(s); } and in each source file one adds a first line #include "procent.h" where procent.h is a file like extern int procent_d(); extern long procent_D(); extern unsigned long procent_U(); extern char procent_c(); extern char *procent_s(); Now lint can do the checking (with lint -options procent.c other_sources ... ). I just posted a program (called printfck.c) doing this to net.sources. (It works fine on the Hack & Quest sources, which is more than 20000 lines of code, but no guarantees are given. One has to be careful with the interaction with the C preprocessor. With lines like #define QUOTE " you'll run into obvious problems.) [P.S. Yes, I know, for most C compilers the parentheses in return (x) are superfluous.]