about summary refs log tree commit diff
path: root/debug/tst-chk1.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-07-20 07:43:27 +0000
committerUlrich Drepper <drepper@redhat.com>2005-07-20 07:43:27 +0000
commitdf6f89692fd7e802f38f944ed73942354a9911f8 (patch)
tree12debd445b11886fcf433fc6f85e9abe615670cc /debug/tst-chk1.c
parent10ffcd52f0578b13b48bdf84e73759353b29b673 (diff)
downloadglibc-df6f89692fd7e802f38f944ed73942354a9911f8.tar.gz
glibc-df6f89692fd7e802f38f944ed73942354a9911f8.tar.xz
glibc-df6f89692fd7e802f38f944ed73942354a9911f8.zip
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
	wcsrtombs, mbsnrtowcs, and wcsnrtombs.
	* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
	wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
	* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
	__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
	* debug/tst-chk1.c: Add tests for new functions.
	* debug/mbsnrtowcs_chk.c: New file.
	* debug/mbsrtowcs_chk.c: New file.
	* debug/wcrtomb_chk.c: New file.
	* debug/wcsnrtombs_chk.c: New file.
	* debug/wcsrtombs_chk.c: New file.

	* include/stdio.h: Add declaration for __fxprintf.
Diffstat (limited to 'debug/tst-chk1.c')
-rw-r--r--debug/tst-chk1.c108
1 files changed, 104 insertions, 4 deletions
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index 47938bbf36..62b0fa6f40 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -76,6 +76,7 @@ char buf[10];
 wchar_t wbuf[10];
 volatile size_t l0;
 volatile char *p;
+volatile wchar_t *wp;
 const char *str1 = "JIHGFEDCBA";
 const char *str2 = "F";
 const char *str3 = "%s%n%s%n";
@@ -502,7 +503,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
+    wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -514,7 +515,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wcpcpy (wbuf + 9, wstr2);
+  wp = wcpcpy (wbuf + 9, wstr2);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -544,7 +545,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
+  wp = wmempcpy (wa.buf1 + 6, L"abcde", l0 + 5);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -562,7 +563,7 @@ do_test (void)
   CHK_FAIL_END
 
   CHK_FAIL_START
-  p = wcpcpy (wa.buf1 + (O + 8), wstr2);
+  wp = wcpcpy (wa.buf1 + (O + 8), wstr2);
   CHK_FAIL_END
 
   CHK_FAIL_START
@@ -1056,6 +1057,105 @@ do_test (void)
 	}
       CHK_FAIL_END
 #endif
+
+      mbstate_t s;
+      memset (&s, '\0', sizeof (s));
+      if (wcrtomb (enough, L'A', &s) != 1)
+	{
+	  puts ("first wcrtomb test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      if (wcrtomb (smallbuf, L'\x100', &s) != 2)
+	{
+	  puts ("second wcrtomb test failed");
+	  ret = 1;
+	}
+      CHK_FAIL_END
+#endif
+
+      wchar_t wenough[10];
+      memset (&s, '\0', sizeof (s));
+      const char *cp = "A";
+      if (mbsrtowcs (wenough, &cp, 10, &s) != 1)
+	{
+	  puts ("first mbsrtowcs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      wchar_t wsmallbuf[2];
+      cp = "ABC";
+      mbsrtowcs (wsmallbuf, &cp, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      cp = "A";
+      if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1)
+	{
+	  puts ("first mbsnrtowcs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      wchar_t wsmallbuf[2];
+      cp = "ABC";
+      mbsnrtowcs (wsmallbuf, &cp, 3, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      const wchar_t *wcp = L"A";
+      if (wcsrtombs (enough, &wcp, 10, &s) != 1)
+	{
+	  puts ("first wcsrtombs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      wcp = L"ABC";
+      wcsrtombs (smallbuf, &wcp, 10, &s);
+      CHK_FAIL_END
+#endif
+
+      memset (&s, '\0', sizeof (s));
+      wcp = L"A";
+      if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1)
+	{
+	  puts ("first wcsnrtombs test failed");
+	  ret = 1;
+	}
+
+#if __USE_FORTIFY_LEVEL >= 1
+      /* We know the wchar_t encoding is ISO 10646.  So pick a
+	 character which has a multibyte representation which does not
+	 fit.  */
+      CHK_FAIL_START
+      char smallbuf[2];
+      wcp = L"ABC";
+      wcsnrtombs (smallbuf, &wcp, 3, 10, &s);
+      CHK_FAIL_END
+#endif
     }
   else
     {