[Skiboot] [PATCH] libc: Remove NULL check for format argument in snprintf()

Stewart Smith stewart at linux.vnet.ibm.com
Mon Jul 18 17:10:40 AEST 2016


Cyril Bur <cyril.bur at au1.ibm.com> writes:
> libc printf style functions are annotated with __attribute__((format
> (printf, x, y))) which causes GCC to perform compile time checks
> against these arguments.
>
> As of at least gcc 6.1.1 [(GCC) 6.1.1 20160602] this causes an error
> running make check. GCC appears to be guaranteeing that the format
> argument won't be NULL and complaining about explicit checks.
>
> In file included from core/test/run-console-log-buf-overrun.c:48:0:
> core/test/run-console-log-buf-overrun.c: In function ‘snprintf’:
> core/test/../../libc/stdio/snprintf.c:21:19: error: nonnull argument
> ‘format’compared to NULL [-Werror=nonnull-compare]
> if ((buff==NULL) || (format==NULL))
>     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors make:
> *** [core/test/Makefile.check:59:core/test/run-console-log-buf-overrun] Error 1
>
> Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
> ---
> I'm not 100% sure this is the fix we want in terms of backwards
> compatibility with older compilers, I'm definitely open to other solutions.
>
> As an other aside (from
> https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Common-Function-Attributes.html):
> "The compiler always (unless -ffreestanding or -fno-builtin is used)
> checks formats for the standard library functions printf, fprintf,
> sprintf, scanf, fscanf, sscanf, strftime, vprintf, vfprintf and
> vsprintf whenever such warnings are requested (using -Wformat), so
> there is no need to modify the header file stdio.h. In C99 mode, the
> functions snprintf, vsnprintf, vscanf, vfscanf and vsscanf are also
> checked. Except in strictly conforming C standard modes, the X/Open
> function strfmon is also checked as are printf_unlocked and
> fprintf_unlocked. See Options Controlling C Dialect."
>
> It looks like GCC actually adds those checks automatically and it is
> working in skiboot. Those annotations aren't hurting so I don't see
> any reason to remove them but it might be worth knowing that removing
> them doesn't change anything...
>
>  libc/stdio/snprintf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Merged to master as of d314ddf5d9e167108ccddf0ed1cdb3cc0f25d443

-- 
Stewart Smith
OPAL Architect, IBM.



More information about the Skiboot mailing list