From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32112 invoked by alias); 19 Dec 2008 01:10:05 -0000 Received: (qmail 31958 invoked by uid 48); 19 Dec 2008 01:08:46 -0000 Date: Fri, 19 Dec 2008 01:10:00 -0000 From: "bruno at clisp dot org" To: glibc-bugs@sources.redhat.com Message-ID: <20081219010845.9674.bruno@clisp.org> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/9674] New: mbtowc keeps internal state even for stateless encodings X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2008-12/txt/msg00089.txt.bz2 Run the following program on a system with a fr_FR.UTF-8 locale. =================================================================== #include #include #include #include int main () { int locale_found = setlocale (LC_ALL, "fr_FR.UTF-8") != NULL; printf ("%d\n", locale_found); printf ("%d\n", mbtowc (NULL, NULL, 0)); static const char input[4] = { 195, 188, 195, 159 }; wchar_t wc; int res2a = mbtowc (&wc, input, 4); printf ("%d\n", res2a); int res1 = mbtowc (&wc, input, 1); printf ("%d\n", res1); int res2b = mbtowc (&wc, input, 4); printf ("%d\n", res2b); return 0; } =================================================================== $ gcc -O -Wall foo.c $ ./a.out 1 0 2 -1 -1 Expected output: 1 0 2 -1 2 Rationale: The first line shows that the locale was correctly set. So the locale encoding is UTF-8. The second line that the UTF-8 encoding is non state dependent. The third and fifth line show that the same call has different results, that is, it must depend on a hidden state. But the mbtowc specification says that "For a state-dependent encoding ... Subsequent calls with s as other than a null pointer shall cause the internal state of the function to be altered as necessary." However, the encoding in use here is not state dependent. Hence the function's results should not depend on hidden state. Reference: POSIX:2008 specification of mbtowc: -- Summary: mbtowc keeps internal state even for stateless encodings Product: glibc Version: 2.8 Status: NEW Severity: normal Priority: P2 Component: libc AssignedTo: drepper at redhat dot com ReportedBy: bruno at clisp dot org CC: glibc-bugs at sources dot redhat dot com GCC build triplet: i686-suse-linux GCC host triplet: i686-suse-linux GCC target triplet: i686-suse-linux http://sourceware.org/bugzilla/show_bug.cgi?id=9674 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.