Skip to content

Commit 31e5fce

Browse files
committed
Fixed two possible issues with an std::string being constructed from nullptr and causing a crash.
1 parent a02d0c4 commit 31e5fce

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/AudioCaptureImpl_SDL.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ std::map<int, std::string> AudioCaptureImpl::AudioDeviceList()
2525

2626
for (int i = 0; i < recordingDeviceCount; i++)
2727
{
28-
deviceList.insert(std::make_pair(i, SDL_GetAudioDeviceName(i, true)));
28+
auto deviceName = SDL_GetAudioDeviceName(i, true);
29+
if (deviceName)
30+
{
31+
deviceList.insert(std::make_pair(i, deviceName));
32+
}
33+
else
34+
{
35+
poco_error_f2(_logger, "Could not get device name for device ID %d: %s", i, std::string(SDL_GetError()));
36+
}
2937
}
3038

3139
return deviceList;
@@ -68,7 +76,14 @@ void AudioCaptureImpl::NextAudioDevice()
6876

6977
std::string AudioCaptureImpl::AudioDeviceName() const
7078
{
71-
return SDL_GetAudioDeviceName(_currentAudioDeviceIndex, true);
79+
if (_currentAudioDeviceIndex >= 0)
80+
{
81+
return SDL_GetAudioDeviceName(_currentAudioDeviceIndex, true);
82+
}
83+
else
84+
{
85+
return "Default capturing device";
86+
}
7287
}
7388

7489
bool AudioCaptureImpl::OpenAudioDevice()

0 commit comments

Comments
 (0)