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

[email protected]
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.