This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
BUG REPORT: glibc 2.2 mbrtowc() fails to decode final byte
- To: bug-glibc at gnu dot org
- Subject: BUG REPORT: glibc 2.2 mbrtowc() fails to decode final byte
- From: Markus Kuhn <Markus dot Kuhn at cl dot cam dot ac dot uk>
- Date: Wed, 10 Jan 2001 20:41:59 +0000
- cc: libc-alpha at sourceware dot cygnus dot com
The following regression test fails in glibc 2.2 under linux-i386:
-------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <wchar.h>
#include <locale.h>
int main() {
// UTF-8 single byte feeding test for mbrtowc()
wchar_t wc;
mbstate_t s;
char *locale = "en_GB.UTF-8";
if (!setlocale(LC_CTYPE,locale)) {
fprintf(stderr, "locale '%s' not available!\n", locale);
exit(1);
}
wc = 42; /* arbitrary number */
assert(mbrtowc(NULL, NULL, 0, &s) == 0); /* get s into initial state */
assert(mbrtowc(&wc, "", 1, &s) == 0); /* test final byte processing */
assert(wc == 0); /* test final byte decoding */
return 0;
}
-------------------------------------------------------------------
The tested behaviour is clearly required by ISO/IEC 9899:1999:
7.24.6.3.2 The mbrtowc function
[...]
[#4] The mbrtowc function returns the first of the following
that applies (given the current conversion state):
0 if the next n or fewer bytes complete the
multibyte character that corresponds to the
null wide character (which is the value
^^^^^^^^^^^^^^^^^^^^^
stored).
^^^^^^
This was first reported by Edmund GRIMLEY EVANS on 2000-11-11.
Markus
--
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org, WWW: <http://www.cl.cam.ac.uk/~mgk25/>