Fix SEGV on unsupported device types

.. train tool segvs on device types that were previously
configured but are no longer supported. This fix now silently
ignores any devices that are no longer supported.

Fixes #497.
This commit is contained in:
Mark Liversedge
2013-02-25 13:37:07 +00:00
parent b35114ef50
commit da495d8700

View File

@@ -69,12 +69,27 @@ DeviceConfigurations::readConfig()
count = configVal.toInt();
}
// get list of supported devices
DeviceTypes all;
// for each device
for (int i=0; i< count; i++) {
DeviceConfiguration Entry;
QString configStr = QString("%1%2").arg(GC_DEV_NAME).arg(i+1);
QString configStr = QString("%1%2").arg(GC_DEV_TYPE).arg(i+1);
configVal = appsettings->value(NULL, configStr);
Entry.type = configVal.toInt();
bool supported = false;
foreach(DeviceType s, all.getList()) {
if (s.type == Entry.type) supported = true;
}
// skip unsupported devices
if (supported == false) continue;
configStr = QString("%1%2").arg(GC_DEV_NAME).arg(i+1);
configVal = appsettings->value(NULL, configStr);
Entry.name = configVal.toString();
@@ -82,10 +97,6 @@ DeviceConfigurations::readConfig()
configVal = appsettings->value(NULL, configStr);
Entry.portSpec = configVal.toString();
configStr = QString("%1%2").arg(GC_DEV_TYPE).arg(i+1);
configVal = appsettings->value(NULL, configStr);
Entry.type = configVal.toInt();
configStr = QString("%1%2").arg(GC_DEV_WHEEL).arg(i+1);
configVal = appsettings->value(NULL, configStr);
Entry.wheelSize = configVal.toInt();