| Summary: | EUC support of wcstombs(3) is broken for codeset 3 and 4 | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | sa2c <sa2c> | ||||
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | 4.3-STABLE | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
State Changed From-To: open->feedback Satoshi-san, do you have any pointers to the specifications for Japanese languages [in English please] so that I get a better understanding of the issues. I committed the fix in CURRENT. Lets wait a while and see if anything goes wrong with this in place. Thanks. Please close this PR. Already committed as euc.c:1.7. State Changed From-To: feedback->closed Closed at submitter's request. |
wcstombs(3) converts wide characters to multibyte characters incorrectly if the character is codeset 3 or codeset 4 of EUC character. The produced multibyte characters do not conform to EUC specifition. How-To-Repeat: #include <locale.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* multibyte Japanese EUC characters */ const unsigned char teststr[] = { 0x41, 0xa4, 0xa2, 0x8e, 0xb1, 0x8f, 0xb0, 0xa1, 0 }; /* expected wide characters of above */ const wchar_t w_teststr[] = { 0x0041, 0xa4a2, 0x00b1, 0xb021, 0 }; void dumpmbs(const char *prompt, const unsigned char *p) { int c; printf("%s: ", prompt); do { c = *p++; printf("[%02x]", c); } while (c != 0); putchar('\n'); } void dumpwcs(const char *prompt, const wchar_t *wp) { wchar_t wc; printf("%s: ", prompt); do { wc = *wp++; printf("[%04x]", wc); } while (wc != 0); putchar('\n'); } int main(int argc, char **argv) { unsigned char buf[BUFSIZ]; wchar_t wbuf[BUFSIZ]; setlocale(LC_CTYPE, "ja_JP.EUC"); strncpy(buf, teststr, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; dumpmbs("mbs", teststr); dumpwcs("wcs", w_teststr); mbstowcs(wbuf, teststr, BUFSIZ); dumpwcs("mbs->wcs", wbuf); wcstombs(buf, w_teststr, BUFSIZ); dumpmbs("wcs->mbs", buf); mbstowcs(wbuf, teststr, BUFSIZ); wcstombs(buf, wbuf, BUFSIZ); dumpmbs("mbs->wcs->mbs", buf); wcstombs(buf, w_teststr, BUFSIZ); mbstowcs(wbuf, buf, BUFSIZ); dumpwcs("wcs->mbs->wcs", wbuf); return 0; }