This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
incorrect wcsrtombs
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: incorrect wcsrtombs
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 24 Apr 2000 13:55:17 +0200 (MET DST)
In glibc-2000-04-12, there is a bug in function wcsrtombs (and also
wcsnrtombs): The test program
====================== test_utf8_wcsrtombs.c =============================
/* Test restarting behaviour of wcsrtombs. */
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>
#define show(expr) { size_t res = expr; printf(#expr " -> %d",res); dst += res; printf(", src = srcbuf+%d, dst = buf+%d\n",src-srcbuf,dst-(char*)buf); }
int main ()
{
unsigned char buf [6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
unsigned char bufcheck [6] = { 0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb };
wchar_t srcbuf [4] = { 0x25, 0x20ac, 0x03bb, 0 };
mbstate_t state;
const wchar_t * src;
char * dst;
setlocale(LC_CTYPE,"de_DE.UTF-8");
memset(&state,0,sizeof(state));
src = srcbuf;
dst = (char *) buf;
show(wcsrtombs(dst,&src,1,&state));
show(wcsrtombs(dst,&src,1,&state));
show(wcsrtombs(dst,&src,3,&state));
show(wcsrtombs(dst,&src,1,&state));
if (memcmp(buf,bufcheck,6)) {
printf("wrong results\n");
}
return 0;
}
/* Expected output:
wcsrtombs(dst,&src,1,&state) -> 1, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,1,&state) -> 1, src = srcbuf+2, dst = buf+2
wcsrtombs(dst,&src,3,&state) -> 3, src = srcbuf+3, dst = buf+5
wcsrtombs(dst,&src,1,&state) -> 1, src = srcbuf+3, dst = buf+6
*/
/* Output of a non-restarting implementation:
wcsrtombs(dst,&src,1,&state) -> 1, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,1,&state) -> 0, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,3,&state) -> 3, src = srcbuf+2, dst = buf+4
wcsrtombs(dst,&src,1,&state) -> 0, src = srcbuf+2, dst = buf+4
wrong results
*/
==========================================================================
$ localedef -c -f UTF8 -i de_DE de_DE.UTF-8
$ ./test_utf8_wcsrtombs
prints
wcsrtombs(dst,&src,1,&state) -> 1, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,1,&state) -> 0, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,3,&state) -> 0, src = srcbuf+1, dst = buf+1
wcsrtombs(dst,&src,1,&state) -> 0, src = srcbuf+1, dst = buf+1
wrong results