printf behaviour with illegal or malformed format string

Sergey Babkin babkin at verizon.net
Tue Dec 13 09:36:56 PST 2005


>From: Poul-Henning Kamp <phk at phk.freebsd.dk>

>In message <20051212223115.46960.qmail at web36306.mail.mud.yahoo.com>, George Paplas writes:
>>
>>
>>--- Poul-Henning Kamp <phk at phk.freebsd.dk> wrote:
>>
>>> >>If it is not set, the format string will be output unformatted in
>>> >>the message "WARNING: Illegal printf() format string: \"...\".
>>> >
>>> >Since this check presumably applies to the entire *printf() family,
>>> >where do you report the error for {s,f}printf()?
>>> 
>>> Whereever the strings was meant to go, what else can I do ?
>>
>>And what if you are doing an sprintf to a buffer smaller than your
>>warning message?
>
>"Too f**king bad"
>
>It's the programmer who's made a mess in the first place, so he
>can't really make many demands in this situation...

Probably the least intrusive thing is to print the original 
message to the best ability of deciphering it, and then
print the error message on stderr (kind of like the message
printed on the first usage of gets() and such).

-SB


More information about the freebsd-arch mailing list