Skip to content

Commit

Permalink
safer nil for float&percent
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jan 15, 2024
1 parent 2568034 commit 2fe2ab9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/libslic3r/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector<FloatOrPerce
{
if (idx < 0) {
for (const FloatOrPercent &v : this->values)
if (!std::isnan(v.value) && v != NIL_VALUE())
if (!(std::isnan(v.value) || v.value == NIL_VALUE().value || v.value > std::numeric_limits<float>::max()))
return false;
return true;
} else {
Expand All @@ -1344,7 +1344,9 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector<FloatOrPerce
double get_float(size_t idx = 0) const override { return get_abs_value(idx, 1.); }

static inline bool is_nil(const boost::any &to_check) {
return std::isnan(boost::any_cast<FloatOrPercent>(to_check).value) || boost::any_cast<FloatOrPercent>(to_check).value == NIL_VALUE().value;
bool ok = std::isnan(boost::any_cast<FloatOrPercent>(to_check).value) || boost::any_cast<FloatOrPercent>(to_check).value == NIL_VALUE().value
|| boost::any_cast<FloatOrPercent>(to_check).value > std::numeric_limits<float>::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()); }
Expand Down Expand Up @@ -1411,7 +1413,7 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector<FloatOrPerce
ss << v.value;
if (v.percent)
ss << "%";
} else if (std::isnan(v.value) || v.value == NIL_VALUE().value) {
} else if (std::isnan(v.value) || v.value == NIL_VALUE().value || v.value > std::numeric_limits<float>::max()) {
if (NULLABLE)
ss << NIL_STR_VALUE;
else
Expand All @@ -1424,8 +1426,8 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector<FloatOrPerce
if (v1.size() != v2.size())
return false;
for (auto it1 = v1.begin(), it2 = v2.begin(); it1 != v1.end(); ++ it1, ++ it2)
if (!(((std::isnan(it1->value) || it1->value == NIL_VALUE().value) &&
(std::isnan(it2->value) || it2->value == NIL_VALUE().value)) ||
if (!(((std::isnan(it1->value) || it1->value == NIL_VALUE().value || it1->value > std::numeric_limits<float>::max()) &&
(std::isnan(it2->value) || it2->value == NIL_VALUE().value || it1->value > std::numeric_limits<float>::max())) ||
*it1 == *it2))
return false;
return true;
Expand All @@ -1436,8 +1438,8 @@ class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector<FloatOrPerce
static bool vectors_lower(const std::vector<FloatOrPercent> &v1, const std::vector<FloatOrPercent> &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 || it1->value > std::numeric_limits<float>::max());
auto null2 = int(std::isnan(it2->value) || it2->value == NIL_VALUE().value || it1->value > std::numeric_limits<float>::max());
return (null1 < null2) || (null1 == null2 && *it1 < *it2);
}
return v1.size() < v2.size();
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/SavePresetDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2fe2ab9

Please sign in to comment.