This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix swprintf (buf, n, L"format")


Hi!

The _FORTIFY_SOURCE swprintf macro will not work if there are no
arguments after format.

2005-07-21  Jakub Jelinek  <jakub@redhat.com>

	* wcsmbs/bits/wchar2.h (swprintf): Remove format argument.
	* debug/tst-chk1.c (do_test): Add test for swprintf with format
	being the last argument.

--- libc/wcsmbs/bits/wchar2.h.jj	2005-07-20 09:35:31.000000000 +0200
+++ libc/wcsmbs/bits/wchar2.h	2005-07-20 09:35:31.000000000 +0200
@@ -199,11 +199,10 @@ extern int __swprintf_chk (wchar_t *__re
      __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 6))) */;
 
 /* XXX We might want to have support in gcc for swprintf.  */
-#define swprintf(s, n, format, ...) \
+#define swprintf(s, n, ...) \
   (__bos (s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1			      \
-   ? __swprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), format,	      \
-		     __VA_ARGS__)					      \
-   : swprintf (s, n, format, __VA_ARGS__))
+   ? __swprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), __VA_ARGS__)   \
+   : swprintf (s, n, __VA_ARGS__))
 
 
 extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
--- libc/debug/tst-chk1.c.jj	2005-07-20 10:32:42.000000000 +0200
+++ libc/debug/tst-chk1.c	2005-07-21 11:23:08.000000000 +0200
@@ -403,6 +403,10 @@ do_test (void)
       || wmemcmp (wbuf, L"aabcEDX98", 10))
     FAIL ();
 
+  if (swprintf (wbuf + 7, 3, L"64") != 2
+      || wmemcmp (wbuf, L"aabcEDX64", 10))
+    FAIL ();
+
   /* These ops need runtime checking, but shouldn't __chk_fail.  */
   wmemcpy (wbuf, L"abcdefghij", l0 + 10);
   wmemmove (wbuf + 1, wbuf, l0 + 9);

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]