diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 035a6ecc1c..f9a7ce5c3a 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -405,14 +405,21 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path) { const char* chars = e->GetStringUTFChars(path, 0); if (chars) { + unsigned length = strlen(chars); + + RUNTIME_ARRAY(char, buffer, length + 3); + memcpy(RUNTIME_ARRAY_BODY(buffer), chars, length); + memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3); + + e->ReleaseStringUTFChars(path, chars); + Directory* d = new (malloc(sizeof(Directory))) Directory; - d->handle = FindFirstFile(chars, &(d->data)); + d->handle = FindFirstFile(buffer, &(d->data)); if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); d = 0; } - e->ReleaseStringUTFChars(path, chars); return reinterpret_cast(d); } else { return 0; diff --git a/src/windows.cpp b/src/windows.cpp index 74aa32b498..f15c2996d2 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -678,8 +678,13 @@ class MySystem: public System { virtual Status open(System::Directory** directory, const char* name) { Status status = 1; + unsigned length = strlen(name); + RUNTIME_ARRAY(char, buffer, length + 3); + memcpy(RUNTIME_ARRAY_BODY(buffer), name, length); + memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3); + Directory* d = new (allocate(this, sizeof(Directory))) Directory(this); - d->handle = FindFirstFile(name, &(d->data)); + d->handle = FindFirstFile(RUNTIME_ARRAY_BODY(buffer), &(d->data)); if (d->handle == INVALID_HANDLE_VALUE) { d->dispose(); } else {