More information about this issue for anyone who's interested.

It seems that return value of mbrtowc is broken only with DBCS code pages. The 
return value is correct when using UCRT's mbrtowc with UTF-8 locales.

The issue with mbrtowc has direct effect on mbsrtowcs:

```
char *str = /* some DBCS string */;
wchar_t buffer[SUFFICIENT_BUFFER_SIZE];
mbstate_t state = {0);
mbrtowc (buffer, str, 1, &state);
str += 1;
mbsrtowcs (buffer, &str, SUFFICIENT_BUFFER_SIZE, &state)
```

Call to `mbrtowc` will return (size_t)-2 and update &state. Call to `mbsrtowcs` 
will correctly convert the first character in str, however, since `mbrtowc` 
returns 2, it skips two bytes in str instead of one as it should. The result is 
either incorrectly converted string or conversion failure, depending on what 
byte is pointed to by str+2.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to