Fix a problem of null-termination with Win32 API
This commit is contained in:
parent
ef7288857a
commit
6c26618dd8
1 changed files with 4 additions and 6 deletions
|
|
@ -13,8 +13,6 @@ namespace SfizzPaths {
|
||||||
|
|
||||||
fs::path getAriaPathSetting(const char* name)
|
fs::path getAriaPathSetting(const char* name)
|
||||||
{
|
{
|
||||||
fs::path path;
|
|
||||||
|
|
||||||
std::unique_ptr<WCHAR[]> nameW;
|
std::unique_ptr<WCHAR[]> nameW;
|
||||||
unsigned nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0);
|
unsigned nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0);
|
||||||
if (nameSize == 0)
|
if (nameSize == 0)
|
||||||
|
|
@ -30,17 +28,17 @@ fs::path getAriaPathSetting(const char* name)
|
||||||
if (status != ERROR_SUCCESS)
|
if (status != ERROR_SUCCESS)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
WCHAR valueW[32768];
|
DWORD valueSize = 32768 * sizeof(WCHAR);
|
||||||
DWORD valueSize = sizeof(valueW);
|
std::unique_ptr<WCHAR[]> valueW(new WCHAR[(valueSize / sizeof(WCHAR)) + 1]());
|
||||||
DWORD valueType;
|
DWORD valueType;
|
||||||
status = RegQueryValueExW(
|
status = RegQueryValueExW(
|
||||||
key, nameW.get(), nullptr,
|
key, nameW.get(), nullptr,
|
||||||
&valueType, reinterpret_cast<LPBYTE>(valueW), &valueSize);
|
&valueType, reinterpret_cast<LPBYTE>(valueW.get()), &valueSize);
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
if (status != ERROR_SUCCESS || (valueType != REG_SZ && valueType != REG_EXPAND_SZ))
|
if (status != ERROR_SUCCESS || (valueType != REG_SZ && valueType != REG_EXPAND_SZ))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return fs::path(valueW);
|
return fs::path(valueW.get());
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
// implementation in SfizzForeignPaths.mm
|
// implementation in SfizzForeignPaths.mm
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue