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:
@@ -485,6 +485,11 @@ std::string AudioManagerWindows::getDeviceName( IMMDevice* device )
|
|||||||
if ( device->OpenPropertyStore( STGM_READ, &pProps ) >= 0
|
if ( device->OpenPropertyStore( STGM_READ, &pProps ) >= 0
|
||||||
&& pProps->GetValue( PKEY_Device_FriendlyName, &varString ) >= 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::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
std::string name = converter.to_bytes( varString.pwszVal );
|
std::string name = converter.to_bytes( varString.pwszVal );
|
||||||
return name;
|
return name;
|
||||||
@@ -497,6 +502,11 @@ std::string AudioManagerWindows::getDeviceId( IMMDevice* device )
|
|||||||
LPWSTR ppstrId;
|
LPWSTR ppstrId;
|
||||||
if ( device->GetId( &ppstrId ) >= 0 )
|
if ( device->GetId( &ppstrId ) >= 0 )
|
||||||
{
|
{
|
||||||
|
if ( ppstrId == nullptr )
|
||||||
|
{
|
||||||
|
return "INVALID-ID";
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
return converter.to_bytes( ppstrId );
|
return converter.to_bytes( ppstrId );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user