better to make a copy than modify the const string

This commit is contained in:
Doug MacEachern 2004-12-06 01:06:15 +00:00
parent 728fd6d75d
commit 25c3a927e7
1 changed files with 15 additions and 6 deletions

View File

@ -111,13 +111,22 @@ JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey)
HKEY hkeyResult = 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);
LPTSTR copy;
/* required under IBM/WebSphere 4.0 for certain keys */
if (lpSubkey[len] != '\0') {
copy = wcsdup(lpSubkey);
copy[len] = '\0';
}
else {
copy = lpSubkey;
}
RegOpenKey((HKEY)hkey, copy, &hkeyResult);
env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);
if (copy != lpSubkey) {
free(copy);
}
return (jlong)hkeyResult;
}