@@ -157,14 +157,19 @@ static INSTALLED_PYTHON installed_pythons[MAX_INSTALLED_PYTHONS];
157157
158158static size_t num_installed_pythons = 0 ;
159159
160- /* to hold SOFTWARE\Python\PythonCore\X.Y\InstallPath */
160+ /*
161+ * To hold SOFTWARE\Python\PythonCore\X.Y...\InstallPath
162+ * The version name can be longer than MAX_VERSION_SIZE, but will be
163+ * truncated to just X.Y for comparisons.
164+ */
161165#define IP_BASE_SIZE 40
162- #define IP_SIZE (IP_BASE_SIZE + MAX_VERSION_SIZE)
166+ #define IP_VERSION_SIZE 8
167+ #define IP_SIZE (IP_BASE_SIZE + IP_VERSION_SIZE)
163168#define CORE_PATH L"SOFTWARE\\Python\\PythonCore"
164169
165170static wchar_t * location_checks [] = {
166171 L"\\" ,
167- L"\\PCBuild\\" ,
172+ L"\\PCBuild\\win32\\ " ,
168173 L"\\PCBuild\\amd64\\" ,
169174 NULL
170175};
@@ -196,6 +201,7 @@ locate_pythons_for_key(HKEY root, REGSAM flags)
196201 BOOL ok ;
197202 DWORD type , data_size , attrs ;
198203 INSTALLED_PYTHON * ip , * pip ;
204+ wchar_t ip_version [IP_VERSION_SIZE ];
199205 wchar_t ip_path [IP_SIZE ];
200206 wchar_t * check ;
201207 wchar_t * * checkp ;
@@ -207,19 +213,21 @@ locate_pythons_for_key(HKEY root, REGSAM flags)
207213 else {
208214 ip = & installed_pythons [num_installed_pythons ];
209215 for (i = 0 ; num_installed_pythons < MAX_INSTALLED_PYTHONS ; i ++ ) {
210- status = RegEnumKeyW (core_root , i , ip -> version , MAX_VERSION_SIZE );
216+ status = RegEnumKeyW (core_root , i , ip_version , IP_VERSION_SIZE );
211217 if (status != ERROR_SUCCESS ) {
212218 if (status != ERROR_NO_MORE_ITEMS ) {
213219 /* unexpected error */
214220 winerror (status , message , MSGSIZE );
215221 debug (L"Can't enumerate registry key for version %ls: %ls\n" ,
216- ip -> version , message );
222+ ip_version , message );
217223 }
218224 break ;
219225 }
220226 else {
227+ wcsncpy_s (ip -> version , MAX_VERSION_SIZE , ip_version ,
228+ MAX_VERSION_SIZE - 1 );
221229 _snwprintf_s (ip_path , IP_SIZE , _TRUNCATE ,
222- L"%ls\\%ls\\InstallPath" , CORE_PATH , ip -> version );
230+ L"%ls\\%ls\\InstallPath" , CORE_PATH , ip_version );
223231 status = RegOpenKeyExW (root , ip_path , 0 , flags , & ip_key );
224232 if (status != ERROR_SUCCESS ) {
225233 winerror (status , message , MSGSIZE );
0 commit comments