This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

restarting behaviour of mbrtowc



In glibc-2000-04-12, there is a bug in the restarting behaviour of mbrtowc:
The test program

====================== test_utf8_mbrtowc.c =============================
/* Test restarting behaviour of mbrtowc. */

#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>

#define show(expr)  printf(#expr " -> %d",expr); printf(", wc = %u\n",wc);

int main ()
{
  unsigned char buf [6] = { 0x25,  0xe2, 0x82, 0xac,  0xce, 0xbb };
  mbstate_t state;
  wchar_t wc = 42;

  setlocale(LC_CTYPE,"de_DE.UTF-8");
  memset(&state,0,sizeof(state));
  show(mbrtowc(&wc,buf+0,1,&state)); /* ->  1, wc = 37 */
  show(mbrtowc(&wc,buf+1,1,&state)); /* -> -2, wc = 37 */
  show(mbrtowc(&wc,buf+2,3,&state)); /* ->  2, wc = 8364 */
  show(mbrtowc(&wc,buf+4,1,&state)); /* -> -2, wc = 8364 */
  show(mbrtowc(&wc,buf+5,1,&state)); /* ->  1, wc = 955 */
  show(mbrtowc(&wc,buf+5,1,&state)); /* -> -1, wc = 955 */

  return 0;
}

/* Expected output:

mbrtowc(&wc,buf+0,1,&state) -> 1, wc = 37
mbrtowc(&wc,buf+1,1,&state) -> -2, wc = 37
mbrtowc(&wc,buf+2,3,&state) -> 2, wc = 8364
mbrtowc(&wc,buf+4,1,&state) -> -2, wc = 8364
mbrtowc(&wc,buf+5,1,&state) -> 1, wc = 955
mbrtowc(&wc,buf+5,1,&state) -> -1, wc = 955

*/
========================================================================

$ localedef -c -f UTF8 -i de_DE de_DE.UTF-8
$ ./test_utf8_mbrtowc

prints

mbrtowc(&wc,buf+0,1,&state) -> 1, wc = 37
mbrtowc(&wc,buf+1,1,&state) -> -2, wc = 37
mbrtowc(&wc,buf+2,3,&state) -> -2, wc = 37   <---- wrong
mbrtowc(&wc,buf+4,1,&state) -> -2, wc = 37
mbrtowc(&wc,buf+5,1,&state) -> -2, wc = 37
mbrtowc(&wc,buf+5,1,&state) -> -1, wc = 37

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]