Skip to content

Commit bf73c43

Browse files
committed
[GR-71005] Fix Encoding mismatch in JVM_GetTemporaryDirectory on Windows.
PullRequest: graal/22472
2 parents 041a915 + ba2700e commit bf73c43

File tree

1 file changed

+6
-5
lines changed
  • substratevm/src/com.oracle.svm.native.jvm.windows/src

1 file changed

+6
-5
lines changed

substratevm/src/com.oracle.svm.native.jvm.windows/src/JvmFuncs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ JNIEXPORT jobject JNICALL JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject acti
248248
}
249249

250250
JNIEXPORT jstring JNICALL JVM_GetTemporaryDirectory(JNIEnv *env) {
251-
// see os_windows.cpp line 1367
252-
static char path_buf[MAX_PATH];
253-
if (GetTempPath(MAX_PATH, path_buf) <= 0) {
254-
path_buf[0] = '\0';
251+
// see os::get_temp_directory() in os_windows.cpp
252+
WCHAR path_buf[MAX_PATH + 1];
253+
DWORD len = GetTempPathW(MAX_PATH + 1, path_buf);
254+
if (len == 0 || len > MAX_PATH + 1) {
255+
return (*env)->NewString(env, NULL, 0); // empty on error/overflow
255256
}
256-
return (*env)->NewStringUTF(env, path_buf);
257+
return (*env)->NewString(env, path_buf, len);
257258
}
258259

259260
jboolean VerifyFixClassname(char *utf_name) {

0 commit comments

Comments
 (0)