BUG REPORT: glibc 2.2 mbrtowc() fails to decode final byte
Andreas Jaeger
aj@suse.de
Thu Jan 11 00:41:00 GMT 2001
>>>>> Ulrich Drepper writes:
> Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> writes:
>> The following regression test fails in glibc 2.2 under linux-i386:
> As Andreas said, this code doesn't fail anymore. But furthermore it's
> incorrect:
>> assert(mbrtowc(NULL, NULL, 0, &s) == 0); /* get s into initial state */
> This is not how initializing a mbstate_t object can work. Since the
> mbrtowc() function can read the mbstate_t object it will read
> uninitialized memory. One has to use memset().
Markus told me I can add the following version to glibc. Uli, is this
ok?
Andreas
2001-01-11 Andreas Jaeger <aj@suse.de>
* localedata/mbrtowc-test.c: New file by Markus Kuhn
<mkuhn@acm.org>.
* localedata/Makefile (tests): Add mbrtowc-test.
(mbrtowc-test-ENV): New.
============================================================
Index: localedata/Makefile
--- localedata/Makefile 2000/12/01 00:16:02 1.80
+++ localedata/Makefile 2001/01/11 08:40:43
@@ -1,4 +1,4 @@
-# Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -90,7 +90,7 @@
tst_wcsxfrm tst_wctob tst_wctomb tst_wctrans \
tst_wctype tst_wcwidth
-tests = $(locale_test_suite) tst-digits tst-setlocale
+tests = $(locale_test_suite) tst-digits tst-setlocale mbrtowc-test
endif
# Files to install.
@@ -254,5 +254,5 @@
tst_wctype-ENV = $(TEST_MBWC_ENV)
tst_wcwidth-ENV = $(TEST_MBWC_ENV)
tst-digits-ENV = $(TEST_MBWC_ENV)
-
+mbrtowc-test-ENV= $(TEST_MBWC_ENV)
tst-setlocale-ENV = LOCPATH=$(common-objpfx)localedata LC_ALL=ja_JP.EUC-JP
============================================================
Index: localedata/mbrtowc-test.c
--- localedata/mbrtowc-test.c created
+++ localedata/mbrtowc-test.c Thu Jan 11 09:18:11 2001 1.1
@@ -0,0 +1,34 @@
+/* Test for mbrtowc, contributed by Markus Kuhn <mkuhn@acm.org>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <wchar.h>
+#include <locale.h>
+
+int
+main (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;
+}
--
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