diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-13 20:30:20 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-13 20:30:20 (GMT) |
commit | 177528494062f82a82280977e5ea3129515cf955 (patch) | |
tree | 1a5d99aaacc895047264c2844f5714bc309fc1df /win/tclWin32Dll.c | |
parent | 3200ec75efb63a3dd964970b75e711592b4866f4 (diff) | |
download | tcl-177528494062f82a82280977e5ea3129515cf955.zip tcl-177528494062f82a82280977e5ea3129515cf955.tar.gz tcl-177528494062f82a82280977e5ea3129515cf955.tar.bz2 |
Fix test-case registry-6.20, which started failing starting with the TIP #389 commit.
Diffstat (limited to 'win/tclWin32Dll.c')
-rw-r--r-- | win/tclWin32Dll.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 74787c5..26da566 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -471,14 +471,28 @@ Tcl_WinUtfToTChar( Tcl_DString *dsPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { - TCHAR *wp; + TCHAR *wp, *p; int size = MultiByteToWideChar(CP_UTF8, 0, string, len, 0, 0); Tcl_DStringInit(dsPtr); Tcl_DStringSetLength(dsPtr, 2*size+2); - wp = (TCHAR *)Tcl_DStringValue(dsPtr); + p = wp = (TCHAR *)Tcl_DStringValue(dsPtr); MultiByteToWideChar(CP_UTF8, 0, string, len, wp, size+1); if (len == -1) --size; /* account for 0-byte at string end */ + + /* It turns out that MultiByteToWideChar() cannot handle the 'modified' + * UTF-8 as used by Tcl. Every sequence of 0xC0 followed by 0x80 will + * be translated to two 0xfffd characters. This results in a test-failure + * of the registry-6.20 test-case. The simplest solution is to search for + * those two 0xfffd characters and replace them by a \u0000 character. */ + while (p < wp + size - 1) { + if (p[0] == 0xfffd && p[1] == 0xfffd) { + memmove(p+1, p+2, sizeof(TCHAR) * (p - wp + size - 2)); + p[0] = 0; + ++p; --size; + } + ++p; + } Tcl_DStringSetLength(dsPtr, 2*size); wp[size] = 0; return wp; |