Skip to content

Commit

Permalink
Fixed crash in AudioSetupToolBar::UpdatePrefs due to use of ...
Browse files Browse the repository at this point in the history
... an uninitialised variable when there are no input channels.

Added null checks before attempting to check the input channels menu
items.
  • Loading branch information
ksoze95 committed Sep 28, 2022
1 parent 59bfa2a commit 8acd7d3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/toolbars/AudioSetupToolBar.cpp
Expand Up @@ -377,15 +377,18 @@ void AudioSetupToolBar::UpdatePrefs()
}
}

long oldChannels;
long oldChannels = 0;
for (const auto & item : mInputChannels->GetMenuItems()) {
if (item->IsChecked())
oldChannels = item->GetId() - kInputChannels + 1;
}

auto newChannels = AudioIORecordChannels.ReadWithDefault(0);
if (newChannels > 0 && oldChannels != newChannels)
mInputChannels->FindChildItem(kInputChannels + newChannels - 1)->Check();
if (newChannels > 0 && oldChannels != newChannels) {
auto item = mInputChannels->FindChildItem(kInputChannels + newChannels - 1);
if (item != nullptr)
item->Check();
}

selectedHost = GetSelectedRadioItemLabel(*mHost);
if (!hostName.empty() && selectedHost && selectedHost != hostName) {
Expand Down Expand Up @@ -624,7 +627,9 @@ void AudioSetupToolBar::FillInputChannels()
newChannels = oldChannels;
}
if (newChannels >= 1) {
mInputChannels->FindItem(kInputChannels + newChannels - 1)->Check();
auto item = mInputChannels->FindItem(kInputChannels + newChannels - 1);
if (item != nullptr)
item->Check();
}
AudioIORecordChannels.Write(newChannels);
break;
Expand Down

0 comments on commit 8acd7d3

Please sign in to comment.