summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-12-28 21:14:40 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-12-28 21:14:40 (GMT)
commitad43c617e3fb81c44639a400b8a6d611aa52e3f2 (patch)
tree3ab00db80ae561e18e8aba09a1ed828b5dab490d
parent301f6bcb839b301e1e3d3a92e3713696780c95ca (diff)
downloadtcl-ad43c617e3fb81c44639a400b8a6d611aa52e3f2.zip
tcl-ad43c617e3fb81c44639a400b8a6d611aa52e3f2.tar.gz
tcl-ad43c617e3fb81c44639a400b8a6d611aa52e3f2.tar.bz2
Fix bug introduced in [0dd0d14489258621] (only for TCL_UTF_MAX > 3): If len parameter = -1, returned size includes terminating 0-byte. So, account for that.
Also, fix some comments which were not accurate any more, now that Windows 95/98 is not supported any more.
-rw-r--r--generic/tclStubInit.c2
-rw-r--r--win/tclWin32Dll.c33
2 files changed, 18 insertions, 17 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 679a12b..b28d501 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -196,6 +196,7 @@ Tcl_WinUtfToTChar(
Tcl_DStringSetLength(dsPtr, 2*size+2);
wp = (WCHAR *)Tcl_DStringValue(dsPtr);
MultiByteToWideChar(CP_UTF8, 0, string, len, wp, size+1);
+ if (len == -1) --size; /* account for 0-byte at string end */
Tcl_DStringSetLength(dsPtr, 2*size);
wp[size] = 0;
return (char *)wp;
@@ -226,6 +227,7 @@ Tcl_WinTCharToUtf(
Tcl_DStringSetLength(dsPtr, size+1);
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 */
Tcl_DStringSetLength(dsPtr, size);
p[size] = 0;
return p;
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c
index 3add0d1..6c973df 100644
--- a/win/tclWin32Dll.c
+++ b/win/tclWin32Dll.c
@@ -519,35 +519,32 @@ TclWinDriveLetterForVolMountPoint(
*
* Tcl_WinUtfToTChar, Tcl_WinTCharToUtf --
*
- * Convert between UTF-8 and Unicode when running Windows NT or the
- * current ANSI code page when running Windows 95.
+ * Convert between UTF-8 and Unicode when running Windows.
*
- * On Mac, Unix, and Windows 95, all strings exchanged between Tcl and
- * the OS are "char" oriented. We need only one Tcl_Encoding to convert
- * between UTF-8 and the system's native encoding. We use NULL to
- * represent that encoding.
+ * On Mac and Unix, all strings exchanged between Tcl and the OS are
+ * "char" oriented. We need only one Tcl_Encoding to convert between
+ * UTF-8 and the system's native encoding. We use NULL to represent
+ * that encoding.
*
- * On NT, some strings exchanged between Tcl and the OS are "char"
+ * On Windows, some strings exchanged between Tcl and the OS are "char"
* oriented, while others are in Unicode. We need two Tcl_Encoding APIs
* depending on whether we are targeting a "char" or Unicode interface.
*
- * Calling Tcl_UtfToExternal() or Tcl_ExternalToUtf() with an encoding of
- * NULL should always used to convert between UTF-8 and the system's
+ * Calling Tcl_UtfToExternal() or Tcl_ExternalToUtf() with an encoding
+ * of NULL should always used to convert between UTF-8 and the system's
* "char" oriented encoding. The following two functions are used in
- * Windows-specific code to convert between UTF-8 and Unicode strings
- * (NT) or "char" strings(95). This saves you the trouble of writing the
+ * Windows-specific code to convert between UTF-8 and Unicode strings.
+ * This saves you the trouble of writing the
* following type of fragment over and over:
*
* encoding <- Tcl_GetEncoding("unicode");
* nativeBuffer <- UtfToExternal(encoding, utfBuffer);
* Tcl_FreeEncoding(encoding);
*
- * By convention, in Windows a TCHAR is a character in the ANSI code page
- * on Windows 95, a Unicode character on Windows NT. If you plan on
- * targeting a Unicode interfaces when running on NT and a "char"
- * oriented interface while running on 95, these functions should be
- * used. If you plan on targetting the same "char" oriented function on
- * both 95 and NT, use Tcl_UtfToExternal() with an encoding of NULL.
+ * By convention, in Windows a TCHAR is a Unicode character. If you plan
+ * on targeting a Unicode interface when running on Windows, these
+ * functions should be used. If you plan on targetting a "char" oriented
+ * function on Windows, use Tcl_UtfToExternal() with an encoding of NULL.
*
* Results:
* The result is a pointer to the string in the desired target encoding.
@@ -576,6 +573,7 @@ Tcl_WinUtfToTChar(
Tcl_DStringSetLength(dsPtr, 2*size+2);
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 */
Tcl_DStringSetLength(dsPtr, 2*size);
wp[size] = 0;
return wp;
@@ -605,6 +603,7 @@ Tcl_WinTCharToUtf(
Tcl_DStringSetLength(dsPtr, size+1);
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 */
Tcl_DStringSetLength(dsPtr, size);
p[size] = 0;
return p;