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

[email protected]
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
With inetd(8), I'm about to achieve adding functionalities, more
information for config checking with, eventually, a smaller exec.

At first, I used macros with VA_ARGS to redirect messages whether to
syslog(3) (daemonized) or to stderr or stdout (foreground mode).

The first blunder was to concatenate a trailing "\n", in the macro,
in the fprintf() case that rendered the format in syslog different from
the format for fprintf which duplicated the string.

But, having corrected that, I realized that using macros was adding a
lot of undue code. It was far more correct to define a my_syslog() procedure
that will do the same without this added code.

But inetd is compiled with WARNS = 6, and this adds -Wformat=2 that
adds -Wformat-nonliteral, and warnings are treated as errors.

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

still getting the warning, but at least not fatal.

Is there a way to please the compiler when using a va_list and calling
syslog(3) or fprintf(3)?

I thought of creating a constant char * const log_msg[] = { ... }; 
with all the formats, and passing an integer as index in this array, but
will this solve this problem?---and is it worth?
-- 
        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.