BUG REPORT: glibc 2.2 mbrtowc() fails to decode final byte
Andreas Jaeger
aj@suse.de
Thu Jan 11 08:02:00 GMT 2001
>>>>> Ulrich Drepper writes:
> Andreas Jaeger <aj@suse.de> writes:
>> Markus told me I can add the following version to glibc. Uli, is this
>> ok?
> The code is OK, but merge it into the wcsmbs/tst-mbrtowc.c file. No
> need to create yet another one.
I agree, here's an updated patch,
Andreas
2001-01-11 Andreas Jaeger <aj@suse.de>
* wcsmbs/tst-mbrtowc.c (utf8_test): New function by Markus Kuhn
<mkuhn@acm.org>.
============================================================
Index: wcsmbs/tst-mbrtowc.c
--- wcsmbs/tst-mbrtowc.c 2000/11/18 20:59:46 1.1
+++ wcsmbs/tst-mbrtowc.c 2001/01/11 16:00:24
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
@@ -26,7 +26,34 @@
static int check_ascii (const char *locname);
+/* Test for mbrtowc, contributed by Markus Kuhn <mkuhn@acm.org>. */
+static int
+utf8_test (void)
+{
+ /* UTF-8 single byte feeding test for mbrtowc(). */
+ wchar_t wc;
+ mbstate_t s;
+ char *locale = "de_DE.UTF-8";
+
+ if (!setlocale (LC_CTYPE, locale))
+ {
+ fprintf (stderr, "locale '%s' not available!\n", locale);
+ exit (1);
+ }
+ wc = 42; /* arbitrary number */
+ memset (&s, 0, sizeof (s)); /* get s into initial state */
+ assert (mbrtowc (&wc, "\xE2", 1, &s) == (size_t) - 2); /* 1st byte processed */
+ assert (mbrtowc (&wc, "\x89", 1, &s) == (size_t) - 2); /* 2nd byte processed */
+ assert (wc == 42); /* no value has not been stored into &wc yet */
+ assert (mbrtowc (&wc, "\xA0", 1, &s) == 1); /* 3nd byte processed */
+ assert (wc == 0x2260); /* E2 89 A0 = U+2260 (not equal) decoded correctly */
+ assert (mbrtowc (&wc, "", 1, &s) == 0); /* test final byte processing */
+ assert (wc == 0); /* test final byte decoding */
+
+ return 0;
+}
+
int
main (void)
{
@@ -40,10 +67,12 @@
setlocale (LC_ALL, "de_DE.UTF-8");
result |= check_ascii (setlocale (LC_ALL, NULL));
-
+ result |= utf8_test ();
+
setlocale (LC_ALL, "ja_JP.EUC-JP");
result |= check_ascii (setlocale (LC_ALL, NULL));
+
return result;
}
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj
More information about the Libc-alpha
mailing list