From 93e7a04f89b3b7f8fef4c36d5597d4c5d50f3349 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 23 Nov 2004 00:22:53 +0000 Subject: [PATCH] fix bug under websphere4.0 jdk, key was not always null terminated --- bindings/java/src/jni/win32/registrykey.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bindings/java/src/jni/win32/registrykey.cpp b/bindings/java/src/jni/win32/registrykey.cpp index 0cd7edba..5c40adc6 100644 --- a/bindings/java/src/jni/win32/registrykey.cpp +++ b/bindings/java/src/jni/win32/registrykey.cpp @@ -109,9 +109,13 @@ JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey) (JNIEnv *env, jclass, jlong hkey, jstring subkey) { HKEY hkeyResult = NULL; - - LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL); + jsize len = env->GetStringLength(subkey); + LPTSTR lpSubkey = (LPTSTR)env->GetStringChars(subkey, NULL); + char orig = lpSubkey[len]; + /* required under IBM/WebSphere 4.0 for certain keys */ + lpSubkey[len] = '\0'; RegOpenKey((HKEY)hkey, lpSubkey, &hkeyResult); + lpSubkey[len] = orig; env->ReleaseStringChars(subkey, (const jchar *)lpSubkey); return (jlong)hkeyResult;