summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-02-23 12:34:58 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-02-23 12:34:58 (GMT)
commitc0f6db4b8165a139a30bd801ca3d8ffb56210940 (patch)
tree69331dc9814668ff6de2d71a0b61e87a09963427
parentbdd6e3f4dfea4d7d47d323b51a660c7c7517a531 (diff)
downloadtcl-c0f6db4b8165a139a30bd801ca3d8ffb56210940.zip
tcl-c0f6db4b8165a139a30bd801ca3d8ffb56210940.tar.gz
tcl-c0f6db4b8165a139a30bd801ca3d8ffb56210940.tar.bz2
Revise buffer-sizes used in GetModuleFileNameW() calls. Available buffer-size reported to GetModuleFileNameW() was not always accurate
-rw-r--r--unix/tclUnixFile.c6
-rw-r--r--win/tclWinFile.c2
-rw-r--r--win/tclWinInit.c12
3 files changed, 10 insertions, 10 deletions
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index 3b09799..f2a6b23 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -43,9 +43,9 @@ TclpFindExecutable(
#ifdef __CYGWIN__
int length;
char buf[PATH_MAX * 2];
- char name[PATH_MAX * TCL_UTF_MAX + 1];
- GetModuleFileNameW(NULL, buf, PATH_MAX);
- cygwin_conv_path(3, buf, name, PATH_MAX);
+ char name[PATH_MAX * 3 + 1];
+ GetModuleFileNameW(NULL, buf, sizeof(buf)/2);
+ cygwin_conv_path(3, buf, name, sizeof(name));
length = strlen(name);
if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) {
/* Strip '.exe' part. */
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index d582664..8df346f 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -852,7 +852,7 @@ TclpFindExecutable(
* create this process.
*/
- if (GetModuleFileNameW(NULL, wName, MAX_PATH) == 0) {
+ if (GetModuleFileNameW(NULL, wName, sizeof(wName)/sizeof(WCHAR)) == 0) {
GetModuleFileNameA(NULL, name, sizeof(name));
/*
diff --git a/win/tclWinInit.c b/win/tclWinInit.c
index 6c34573..2abcd3e 100644
--- a/win/tclWinInit.c
+++ b/win/tclWinInit.c
@@ -342,11 +342,11 @@ InitializeDefaultLibraryDir(
{
HMODULE hModule = TclWinGetTclInstance();
WCHAR wName[MAX_PATH + LIBRARY_SIZE];
- char name[(MAX_PATH + LIBRARY_SIZE) * TCL_UTF_MAX];
+ char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- if (GetModuleFileNameW(hModule, wName, MAX_PATH) == 0) {
- GetModuleFileNameA(hModule, name, MAX_PATH);
+ if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) {
+ GetModuleFileNameA(hModule, name, sizeof(name));
} else {
ToUtf(wName, name);
}
@@ -393,11 +393,11 @@ InitializeSourceLibraryDir(
{
HMODULE hModule = TclWinGetTclInstance();
WCHAR wName[MAX_PATH + LIBRARY_SIZE];
- char name[(MAX_PATH + LIBRARY_SIZE) * TCL_UTF_MAX];
+ char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- if (GetModuleFileNameW(hModule, wName, MAX_PATH) == 0) {
- GetModuleFileNameA(hModule, name, MAX_PATH);
+ if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) {
+ GetModuleFileNameA(hModule, name, sizeof(name));
} else {
ToUtf(wName, name);
}