Index: PC/_winreg.c =================================================================== --- PC/_winreg.c (revision 84990) +++ PC/_winreg.c (working copy) @@ -1193,19 +1193,27 @@ DWORD typ; PyObject *obData; PyObject *retVal; + CPINFO info; if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) return NULL; if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) return NULL; + if (!GetCPInfo(CP_ACP, &info)) + return PyErr_SetFromWindowsErrWithFunction(GetLastError(), + "GetCPInfo"); + assert(info.MaxCharSize >= 1); + if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &retValueSize, &retDataSize, NULL, NULL)) != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey"); - ++retValueSize; /* include null terminators */ + /* This value should be large enough to store the value name in ANSI + characters. (include null terminator) */ + retValueSize = (retValueSize * info.MaxCharSize) + 1; ++retDataSize; bufDataSize = retDataSize; bufValueSize = retValueSize;