warning spew from cddl libnvpair.c

Joerg Sonnenberger joerg at britannica.bec.de
Fri Oct 25 11:40:05 UTC 2013


On Thu, Oct 24, 2013 at 11:49:17PM -0400, Sean Bruno wrote:
> libnvpair.c has some macros and preprocessor directives that make
> clang's -Wformat-security very unhappy.
> 
> /home/sbruno/bsd/head/cddl/lib/libnvpair/../../../cddl/contrib/opensolaris/lib/libnvpair/libnvpair.c:245:1: warning: format string is not a string literal (po
> tentially insecure) [-Wformat-security]
> NVLIST_ARRPRTFUNC(byte_array, uchar_t, uchar_t, "0x%2.2x")
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/sbruno/bsd/head/cddl/lib/libnvpair/../../../cddl/contrib/opensolaris/lib/libnvpair/libnvpair.c:238:23: note: expanded from macro 'NVLIST_ARRPRTFUNC'
>                         (void) fprintf(fp, pctl->nvprt_btwnarrfmt); \
> 
> 
> I don't see a real graceful way out of this.  Also, this is totally
> "legit" C, so I don't see any reason to generate these warnings.  Can
> someone educate me on either:
>   1.  fixing these warnings the right way
>   2.  how to disable the warning flags/makefile magic

You can wrap the statement with

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
// Evil code here
#pragma GCC diagnostic pop

and/or use the corresponding _Pragma.

Joerg


More information about the freebsd-hackers mailing list