tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: WARNS > 3 then -Wformat=2: pb with va_list



Le Tue, Jun 20, 2023 at 09:57:43AM -0400, Mouse a écrit :
> > But inetd is compiled with WARNS = 6, and this adds -Wformat=2 that
> > adds -Wformat-nonliteral, [...]
> 
> > Since the compiler is unable to check in my_syslog(prio, fmt, ...)
> > the fmt against the args, it chokes.
> 
> > I added:
> 
> > CFLAGS+=-Wno-error=format-nonliteral
> 
> Did you decorate my_syslog with a suitable
> __attribute__((__format__(...)))?

Thanks for the tip. But I tried this (taking the definition of cdefs.h):

void __printflike(2, 3)
my_syslog(int prio, const char *msg, ...)
{ ... }

but this does not impress gcc in the least...

> 
> If so, and that didn't help, my preferred reaction would be
> -Wno-format-nonliteral.  I believe warnings are there to be servants,
> not masters, and when they get in the way of writing clear, correct
> code, they should be disabled.
> 
> Of course, doing that increases the risk that a future change will
> introduce an error that goes uncaught as a result.  It's a judgement
> call whether the price is worth the benefit.  You could isolate
> my_syslog in its own source file and build only that file with whatever
> -W options you pick, if you want to limit the possible risk.

I will probably go this route putting my_syslog() in a separate file. I
will try the idea of an array of fmt, but I fail to see how this could
add an information that the compiler doesn't have...
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index