[Skiboot] [PATCH] libc: Remove NULL check for format argument in snprintf()
cyril.bur at au1.ibm.com
Thu Jul 14 11:58:52 AEST 2016
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
"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(-)
diff --git a/libc/stdio/snprintf.c b/libc/stdio/snprintf.c
index cc1cc0f..35b6f86 100644
@@ -18,7 +18,7 @@ int snprintf(char *buff, size_t size, const char *format, ...)
- if ((buff==NULL) || (format==NULL))
+ if (buff==NULL)
More information about the Skiboot