lint won't verify printf formatting against variable types??
Steve Rudek
stever at tree.UUCP
Fri Jun 23 08:32:29 AEST 1989
I was surprised to discover that neither cc nor lint comments when printf
formatting doesn't match variable types--I thought lint complained about
everything! In other words, lint won't comment on the following:
int x;
long y;
printf ("x=%ld y=%d", x, y);
I'm trying to get a game called "conquer" to work on a Microport SysV/AT
machine where ints are 16 bits rather than the 32 bits the author expected.
After wrestling with variable overflow for a while, I figured the "good enough"
solution would be to just change most int definitions to INT and #define
INT as long. Then I would count on cc or lint to detect all the %d formatting
which needed to be changed to %ld. Wrongo. cc and lint are both completely
blind to the misformatting! I find that incredible. Oh, I understand that
the formatting argument to printf is just a string pointer, but I'm aghast
that there appears to be no easy way to detect what must be a super common
coding bug! The printf family is enough of a fixture in the C language and
this is a common enough sort of error that lint really should be responsible
for catching this sort of misformat.
Am I missing something or do I really need a custom program to detect this
kind of mistake? If so, do I have to write it myself or has someone out
there already written the program??
P.S. Can anyone direct me to Ed Barlow, the author of "conquer", or to the
latest version? I'm hacking on version 2.2.
--
----------
Steve Rudek {ucbvax!ucdavis!csusac OR ames!pacbell!sactoh0} !tree!stever
More information about the Comp.lang.c
mailing list