From 1013e5f9c1d8a9ee599a98b207ad6c5e57dffeed Mon Sep 17 00:00:00 2001 From: supermerill Date: Sat, 13 Jan 2024 01:03:45 +0100 Subject: [PATCH] safer nil for float&percent --- src/libslic3r/Config.hpp | 16 +++++++++------- src/slic3r/GUI/SavePresetDialog.cpp | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 4e04b03d2b0..8e13ecdf5fa 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1326,7 +1326,7 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVectorvalues) - if (!std::isnan(v.value) && v != NIL_VALUE()) + if (!(std::isnan(v.value) || v.value == NIL_VALUE().value || v.value > std::numeric_limits::max())) return false; return true; } else { @@ -1344,7 +1344,9 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector(to_check).value) || boost::any_cast(to_check).value == NIL_VALUE().value; + bool ok = std::isnan(boost::any_cast(to_check).value) || boost::any_cast(to_check).value == NIL_VALUE().value + || boost::any_cast(to_check).value > std::numeric_limits::max(); + return ok; } // don't use it to compare, use is_nil() to check. static inline boost::any create_nil() { return boost::any(NIL_VALUE()); } @@ -1411,7 +1413,7 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector std::numeric_limits::max()) { if (NULLABLE) ss << NIL_STR_VALUE; else @@ -1424,8 +1426,8 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVectorvalue) || it1->value == NIL_VALUE().value) && - (std::isnan(it2->value) || it2->value == NIL_VALUE().value)) || + if (!(((std::isnan(it1->value) || it1->value == NIL_VALUE().value || v.value > std::numeric_limits::max()) && + (std::isnan(it2->value) || it2->value == NIL_VALUE().value || v.value > std::numeric_limits::max())) || *it1 == *it2)) return false; return true; @@ -1436,8 +1438,8 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector &v1, const std::vector &v2) { if (NULLABLE) { for (auto it1 = v1.begin(), it2 = v2.begin(); it1 != v1.end() && it2 != v2.end(); ++ it1, ++ it2) { - auto null1 = int(std::isnan(it1->value) || it1->value == NIL_VALUE().value); - auto null2 = int(std::isnan(it2->value) || it2->value == NIL_VALUE().value); + auto null1 = int(std::isnan(it1->value) || it1->value == NIL_VALUE().value || v.value > std::numeric_limits::max()); + auto null2 = int(std::isnan(it2->value) || it2->value == NIL_VALUE().value || v.value > std::numeric_limits::max()); return (null1 < null2) || (null1 == null2 && *it1 < *it2); } return v1.size() < v2.size(); diff --git a/src/slic3r/GUI/SavePresetDialog.cpp b/src/slic3r/GUI/SavePresetDialog.cpp index 59418c3f89c..3f30d8e8715 100644 --- a/src/slic3r/GUI/SavePresetDialog.cpp +++ b/src/slic3r/GUI/SavePresetDialog.cpp @@ -124,7 +124,7 @@ void SavePresetDialog::Item::update() } if (m_valid_type == Valid && existing && (existing->is_external)) { - info_line = _L("Cannot overwrite an external profile."); + info_line = _L("Cannot overwrite an external profile. Please choose another name."); m_valid_type = NoValid; }