From da495d87006455be9cf8a1be88c80a1bf4b7dd44 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 25 Feb 2013 13:37:07 +0000 Subject: [PATCH] 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. --- src/DeviceConfiguration.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/DeviceConfiguration.cpp b/src/DeviceConfiguration.cpp index d840b8de2..ab8ba9c4c 100644 --- a/src/DeviceConfiguration.cpp +++ b/src/DeviceConfiguration.cpp @@ -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();