With gcc-4.4.5 patched with defaults-format-security.patch, coreutils emit test-xvasprintf.c: In function 'test_xasprintf': test-xvasprintf.c:98: warning: format not a string literal and no format arguments
There is a gnulib-tests/Makefile hack preventing the warning in case coreutils is compiled with --enable-gcc-warnings but the hack is not triggered when gcc default behavior is changed or -Wformat-security is in CFLAGS. Remove the code hack preventing format-zero-length warning and replace by a pragma GCC diagnostic ignored in top of code. That way, there is no more string literal warning and gnulib-tests/Makefile hack could be removed. Signed-off-by: Gilles Espinasse <g....@free.fr> --- tests/test-xvasprintf.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test-xvasprintf.c b/tests/test-xvasprintf.c index 4a90059..4c281f1 100644 --- a/tests/test-xvasprintf.c +++ b/tests/test-xvasprintf.c @@ -16,6 +16,9 @@ /* Written by Bruno Haible <br...@clisp.org>, 2007. */ + /* Silence gcc warning */ +#pragma GCC diagnostic ignored "-Wformat-zero-length" + #include <config.h> #include "xvasprintf.h" @@ -54,9 +57,7 @@ test_xvasprintf (void) } { - /* Silence gcc warning about zero-length format string. */ - const char *empty = ""; - result = my_xasprintf (empty); + result = my_xasprintf (""); ASSERT (result != NULL); ASSERT (strcmp (result, "") == 0); free (result); @@ -93,9 +94,7 @@ test_xasprintf (void) } { - /* Silence gcc warning about zero-length format string. */ - const char *empty = ""; - result = xasprintf (empty); + result = xasprintf (""); ASSERT (result != NULL); ASSERT (strcmp (result, "") == 0); free (result); -- 1.5.6.5