bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] fix not a string literal warning in test_xasprintf


From: Gilles Espinasse
Subject: [PATCH v2] fix not a string literal warning in test_xasprintf
Date: Mon, 2 Apr 2012 20:20:34 +0200

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 <address@hidden>
---
 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 <address@hidden>, 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]