Add null check to AudioManagerWindow getDeviceName/Id

Windows was returning a nullptr on arbitrary devices, leading to a
SEGFAULT.

"INVALID-NAME" was chosen to be distinguishable from an empty string.
This commit is contained in:
Vasily
2020-01-30 10:36:21 +01:00
committed by username223
parent 7b9f7e6ff3
commit 827d46e48b
@@ -485,6 +485,11 @@ std::string AudioManagerWindows::getDeviceName( IMMDevice* device )
if ( device->OpenPropertyStore( STGM_READ, &pProps ) >= 0
&& pProps->GetValue( PKEY_Device_FriendlyName, &varString ) >= 0 )
{
if ( varString.pwszVal == nullptr )
{
return "INVALID-NAME";
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string name = converter.to_bytes( varString.pwszVal );
return name;
@@ -497,6 +502,11 @@ std::string AudioManagerWindows::getDeviceId( IMMDevice* device )
LPWSTR ppstrId;
if ( device->GetId( &ppstrId ) >= 0 )
{
if ( ppstrId == nullptr )
{
return "INVALID-ID";
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes( ppstrId );
}