Skip to content

Commit

Permalink
Fix #634 plus #534: bound checking in SDRDevices dialog selection
Browse files Browse the repository at this point in the history
  • Loading branch information
vsonnier committed Mar 21, 2018
1 parent 225a795 commit 4cd8735
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/forms/SDRDevices/SDRDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
wxPGProperty *prop = runtimeProps[arg.key];

if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
settingArgs[arg.key] = arg.options[prop->GetChoiceSelection()];
settingArgs[arg.key] = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
settingArgs[arg.key] = (prop->GetValueAsString()=="True")?"true":"false";
} else {
Expand All @@ -378,7 +378,7 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
wxPGProperty *prop = streamProps[arg.key];

if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
streamArgs[arg.key] = arg.options[prop->GetChoiceSelection()];
streamArgs[arg.key] = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
streamArgs[arg.key] = (prop->GetValueAsString()=="True")?"true":"false";
} else {
Expand Down Expand Up @@ -491,6 +491,31 @@ void SDRDevicesDialog::OnRefreshDevices( wxMouseEvent& /* event */) {
doRefreshDevices();
}

std::string SDRDevicesDialog::getSelectedChoiceOption(wxPGProperty* prop, const SoapySDR::ArgInfo& arg) {

std::string optionName = "";

int choiceIndex = prop->GetChoiceSelection();

if (arg.options.size() > 0) {

if (choiceIndex >= 0 && choiceIndex < arg.options.size()) {
//normal selection
optionName = arg.options[choiceIndex];
} else if (choiceIndex >= arg.options.size()) {
//choose the last one of the list:
optionName = arg.options[arg.options.size() - 1];
prop->SetChoiceSelection(arg.options.size() - 1);
} else if (choiceIndex < 0) {
//choose the first one of the list:
optionName = arg.options[0];
prop->SetChoiceSelection(0);
}
}

return optionName;
}

void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {

if (event.GetProperty() == devSettings["name"]) {
Expand Down Expand Up @@ -557,7 +582,7 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
std::string settingValue = prop->GetValueAsString().ToStdString();
SoapySDR::ArgInfo arg = runtimeArgs[rtp->first];
if (arg.type == SoapySDR::ArgInfo::STRING && arg.options.size()) {
settingValue = arg.options[prop->GetChoiceSelection()];
settingValue = getSelectedChoiceOption(prop, arg);
} else if (arg.type == SoapySDR::ArgInfo::BOOL) {
settingValue = (prop->GetValueAsString()=="True")?"true":"false";
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/forms/SDRDevices/SDRDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class SDRDevicesDialog: public devFrame {
SDRDeviceInfo *getSelectedDevice(wxTreeItemId selId);
wxPGProperty *addArgInfoProperty(wxPropertyGrid *pg, SoapySDR::ArgInfo arg);

//
std::string getSelectedChoiceOption(wxPGProperty* prop, const SoapySDR::ArgInfo& arg);


bool refresh, failed;
std::map<std::string, std::vector<SDRDeviceInfo *>* > devs;
std::vector<SDRDeviceInfo *>::iterator devs_i;
Expand Down

0 comments on commit 4cd8735

Please sign in to comment.