Skip to content

Commit

Permalink
Fix #635 plus #534: bound checking in SDRDevices dialog selection
Browse files Browse the repository at this point in the history
vsonnier committed Mar 21, 2018
1 parent 225a795 commit b6b0f85
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
@@ -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 {
@@ -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 {
@@ -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"]) {
@@ -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 {
4 changes: 4 additions & 0 deletions src/forms/SDRDevices/SDRDevices.h
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b6b0f85

Please sign in to comment.