Skip to content
Snippets Groups Projects
Commit 7e7d0f07 authored by Sébastien Blin's avatar Sébastien Blin Committed by Kateryna Kostiuk
Browse files

avmodel: avoid bad_alloc


Change-Id: Idcbd748900708f8e1de4de5196f272ab0b73f887
Reviewed-by: default avatarKateryna <Kostiuk&lt;kateryna.kostiuk@savoirfairelinux.com>
parent 08df7d47
No related branches found
No related tags found
No related merge requests found
......@@ -644,15 +644,38 @@ std::string
AVModelPimpl::getDevice(int type) const
{
if (type < 0 || type > 2) return {}; // No device
auto outputDevices = linked_.getAudioOutputDevices();
std::string result = "";
std::vector<std::string> devices;
switch (type) {
case 0: // INPUT
devices = linked_.getAudioInputDevices();
break;
case 1: // OUTPUT
case 2: // RINGTONE
devices = linked_.getAudioOutputDevices();
break;
default:
break;
}
QStringList currentDevicesIdx = ConfigurationManager::instance()
.getCurrentAudioDevicesIndex();
try {
if (currentDevicesIdx.size() < 3
|| outputDevices.size() != static_cast<size_t>(currentDevicesIdx.size())) {
|| devices.size() != static_cast<size_t>(currentDevicesIdx.size())) {
// Should not happen, but cannot retrieve current ringtone device
return "";
}
return outputDevices[currentDevicesIdx[type].toUInt()];
auto deviceIdx = currentDevicesIdx[type].toUInt();
if (deviceIdx >= devices.size()) {
// Incorrect device index
result = devices[0];
}
result = devices[deviceIdx];
} catch (std::bad_alloc& ba) {
qWarning() << "bad_alloc caught: " << ba.what();
return "";
}
return result;
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment