diff --git a/src/controllers/legacycontrollersettings.h b/src/controllers/legacycontrollersettings.h index b7d2f378d9c7..a259da5719cb 100644 --- a/src/controllers/legacycontrollersettings.h +++ b/src/controllers/legacycontrollersettings.h @@ -259,11 +259,16 @@ class LegacyControllerNumberSetting /// and a strictly positive step, strictly less than max.. /// @return true if valid bool valid() const override { + static constexpr bool typeSize = sizeof(long) == sizeof(int); return AbstractLegacyControllerSetting::valid() && m_defaultValue >= m_minValue && m_savedValue >= m_minValue && m_editedValue >= m_minValue && m_defaultValue <= m_maxValue && m_savedValue <= m_maxValue && m_editedValue <= m_maxValue && - m_stepValue > 0 && m_stepValue < m_maxValue; + m_stepValue > 0 && + (typeSize || + static_cast(m_stepValue) < + static_cast(m_maxValue) - + static_cast(m_minValue)); } static AbstractLegacyControllerSetting* createFrom(const QDomElement& element) { diff --git a/src/test/controller_mapping_settings_test.cpp b/src/test/controller_mapping_settings_test.cpp index 3719fcefaf4e..9689f5a6c279 100644 --- a/src/test/controller_mapping_settings_test.cpp +++ b/src/test/controller_mapping_settings_test.cpp @@ -511,3 +511,38 @@ TEST_F(LegacyControllerMappingSettingsTest, discardDuplicateSettings) { ASSERT_EQ(settings.at(1)->value().toNumber(), 50); ASSERT_EQ(settings.at(2)->value().toString(), "myOptionValue1"); } + +TEST_F(LegacyControllerMappingSettingsTest, handleNumberWithNegativeRange) { + QDomDocument doc; + QString dom; + QTextStream(&dom) + << QString(kValidInteger).arg("0", "-500", "0", "1"); + doc.setContent( + QString("%1") + .arg(dom)); + + auto pMapping = LegacyDummyMappingFileHandler::loadDummyMapping( + doc.documentElement(), "/fake/path"); + + ASSERT_EQ(pMapping->getSettings().size(), 1); + ASSERT_EQ(pMapping->getSettings().at(0)->variableName(), "myInteger1"); + ASSERT_EQ(pMapping->getSettings().at(0)->value().toNumber(), 0); + + dom.clear(); + QTextStream(&dom) + << QString(kValidInteger).arg("20", "-100", "100", "50"); + doc.setContent( + QString("%1") + .arg(dom)); + + pMapping = LegacyDummyMappingFileHandler::loadDummyMapping( + doc.documentElement(), "/fake/path"); + + ASSERT_EQ(pMapping->getSettings().size(), 1); + ASSERT_EQ(pMapping->getSettings().at(0)->variableName(), "myInteger1"); + ASSERT_EQ(pMapping->getSettings().at(0)->value().toNumber(), 20); +}