bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] printf: remove stupid restriction on %n


From: Andreas Schwab
Subject: [PATCH] printf: remove stupid restriction on %n
Date: Mon, 03 Sep 2012 20:19:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

* m4/printf.m4 (gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N):
Remove fmtstring and use a string literal.
---
 m4/printf.m4 | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/m4/printf.m4 b/m4/printf.m4
index 751e896..4b6c9d8 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -631,7 +631,6 @@ invalid_parameter_handler (const wchar_t *expression,
   exit (1);
 }
 #endif
-static char fmtstring[10];
 static char buf[100];
 int main ()
 {
@@ -639,11 +638,7 @@ int main ()
 #ifdef _MSC_VER
   _set_invalid_parameter_handler (invalid_parameter_handler);
 #endif
-  /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
-     support %n in format strings in read-only memory but not in writable
-     memory.  */
-  strcpy (fmtstring, "%d %n");
-  if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
+  if (sprintf (buf, "%d %n", 123, &count, 33, 44, 55) < 0
       || strcmp (buf, "123 ") != 0
       || count != 4)
     return 1;
@@ -1294,16 +1289,11 @@ static int my_snprintf (char *buf, int size, const char 
*format, ...)
   return ret;
 }
 #endif
-static char fmtstring[10];
 static char buf[100];
 int main ()
 {
   int count = -1;
-  /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
-     support %n in format strings in read-only memory but not in writable
-     memory.  */
-  strcpy (fmtstring, "%d %n");
-  my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
+  my_snprintf (buf, 4, "%d %n", 12345, &count, 33, 44, 55);
   if (count != 6)
     return 1;
   return 0;
-- 
1.7.12


-- 
Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



reply via email to

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