From d521ee7cf2ff949f03272f934d544d43874bc25b Mon Sep 17 00:00:00 2001 From: "jinhyung.jo" Date: Wed, 2 Sep 2015 14:51:14 +0900 Subject: [PATCH] emulator: Fixed a bug Java path not found on Windows 64 The get_java_path function aways returns the first item of the JRE(or JDK) registry. The RegEnumKeyEx function's 4th argument type is [In, Out], But previous implementations have used without resetting it. So fix it and improved the 'while' statement. Change-Id: Ief77879c1b6be8f02fbc36e5c7d118152984e371 Signed-off-by: Jinhyung Jo (cherry picked from commit 812b3ccac697ae0d026bb7ea911b95aaa7f04921) --- util/oslib-win32.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index b5beed56ee..22bdb0b212 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -101,20 +101,18 @@ bool get_java_path(char **java_path) } if (res == ERROR_SUCCESS) { - RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - strcpy(strChoosenName, strSubKeyName); - - index = 1; - while (ERROR_SUCCESS == - RegEnumKeyEx(hKey, index, - (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL)) { + index = 0; + do { + dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; + res = RegEnumKeyEx(hKey, + index++, + (LPSTR)strSubKeyName, + &dwSubKeyNameMax, + NULL, NULL, NULL, NULL); if (strcmp(strChoosenName, strSubKeyName) < 0) { strcpy(strChoosenName, strSubKeyName); } - index++; - } + } while (res == ERROR_SUCCESS); RegOpenKeyEx(hKey, strChoosenName, 0, KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey); -- 2.34.1