From a7eda7cc8e26601fe7efc25a65e805fb0a017214 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 26 Jan 2023 21:26:31 +0100 Subject: [PATCH] Fixed is_nil(size_t) when checking out-of-range element: the behaviour should math get_at, which returns first element in case the index is out of range. --- src/libslic3r/Config.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 23be26ee7..c0c7abba0 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -615,7 +615,7 @@ public: static double nil_value() { return std::numeric_limits::quiet_NaN(); } // A scalar is nil, or all values of a vector are nil. bool is_nil() const override { for (auto v : this->values) if (! std::isnan(v)) return false; return true; } - bool is_nil(size_t idx) const override { return std::isnan(this->values[idx]); } + bool is_nil(size_t idx) const override { return std::isnan(this->values[idx < values.size() ? idx : 0]); } std::string serialize() const override { @@ -1092,7 +1092,7 @@ public: static FloatOrPercent nil_value() { return { std::numeric_limits::quiet_NaN(), false }; } // A scalar is nil, or all values of a vector are nil. bool is_nil() const override { for (auto v : this->values) if (! std::isnan(v.value)) return false; return true; } - bool is_nil(size_t idx) const override { return std::isnan(this->values[idx].value); } + bool is_nil(size_t idx) const override { return std::isnan(this->values[idx < values.size() ? idx : 0].value); } std::string serialize() const override { @@ -1404,7 +1404,7 @@ public: static unsigned char nil_value() { return std::numeric_limits::max(); } // A scalar is nil, or all values of a vector are nil. bool is_nil() const override { for (auto v : this->values) if (v != nil_value()) return false; return true; } - bool is_nil(size_t idx) const override { return this->values[idx] == nil_value(); } + bool is_nil(size_t idx) const override { return this->values[idx < values.size() ? idx : 0] == nil_value(); } bool& get_at(size_t i) { assert(! this->values.empty());