diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-24 23:24:00 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-24 23:24:00 (GMT) |
commit | ac61d77a4196e4243153563d9cae24f2f20550bc (patch) | |
tree | 1824f349b3f9fc4e7eac9fb3c9c1a545c05b9643 /win/tclWin32Dll.c | |
parent | d0fab957805e1c6114f06e8442e6f661a675e263 (diff) | |
download | tcl-ac61d77a4196e4243153563d9cae24f2f20550bc.zip tcl-ac61d77a4196e4243153563d9cae24f2f20550bc.tar.gz tcl-ac61d77a4196e4243153563d9cae24f2f20550bc.tar.bz2 |
More fixes in Tcl_WinTChar2Utf: Don't restart loop when output contains null-byte.
Diffstat (limited to 'win/tclWin32Dll.c')
-rw-r--r-- | win/tclWin32Dll.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 13a3dec..60edbab 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -506,8 +506,8 @@ Tcl_WinTCharToUtf( Tcl_DString *dsPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { - char *p, *r; - int size; + char *p; + int size, i = 0; if (len > 0) { len /= 2; @@ -515,18 +515,18 @@ Tcl_WinTCharToUtf( size = WideCharToMultiByte(CP_UTF8, 0, string, len, 0, 0, NULL, NULL); Tcl_DStringInit(dsPtr); Tcl_DStringSetLength(dsPtr, size+8); /* Add some spare, in case of NULL-bytes */ - r = p = (char *)Tcl_DStringValue(dsPtr); + p = (char *)Tcl_DStringValue(dsPtr); WideCharToMultiByte(CP_UTF8, 0, string, len, p, size, NULL, NULL); if (len == -1) --size; /* account for 0-byte at string end */ - while (r < p+size) { - if (!*r) { + while (i < size) { + if (!p[i]) { /* Output contains '\0'-byte, but Tcl expect two-bytes: C0 80 */ - memmove(r+2, r+1, p-r+size-1); - memcpy(r++, "\xC0\x80", 2); + memmove(p+i+2, p+i+1, size-i-1); + memcpy(p + i++, "\xC0\x80", 2); Tcl_DStringSetLength(dsPtr, ++size + 1); - r = p = (char *)Tcl_DStringValue(dsPtr); + p = (char *)Tcl_DStringValue(dsPtr); } - ++r; + ++i; } Tcl_DStringSetLength(dsPtr, size); p[size] = 0; |