mirror of
https://github.com/esphome/esphome.git
synced 2024-12-18 15:57:58 +01:00
Fix crash when using addressable_set with out-of-range indices (#2120)
This commit is contained in:
parent
0d104776bc
commit
cb21c7c18d
@ -159,8 +159,14 @@ template<typename... Ts> class AddressableSet : public Action<Ts...> {
|
|||||||
|
|
||||||
void play(Ts... x) override {
|
void play(Ts... x) override {
|
||||||
auto *out = (AddressableLight *) this->parent_->get_output();
|
auto *out = (AddressableLight *) this->parent_->get_output();
|
||||||
int32_t range_from = this->range_from_.value_or(x..., 0);
|
int32_t range_from = interpret_index(this->range_from_.value_or(x..., 0), out->size());
|
||||||
int32_t range_to = this->range_to_.value_or(x..., out->size() - 1) + 1;
|
if (range_from < 0 || range_from >= out->size())
|
||||||
|
range_from = 0;
|
||||||
|
|
||||||
|
int32_t range_to = interpret_index(this->range_to_.value_or(x..., out->size() - 1) + 1, out->size());
|
||||||
|
if (range_to < 0 || range_to >= out->size())
|
||||||
|
range_to = out->size();
|
||||||
|
|
||||||
uint8_t color_brightness =
|
uint8_t color_brightness =
|
||||||
to_uint8_scale(this->color_brightness_.value_or(x..., this->parent_->remote_values.get_color_brightness()));
|
to_uint8_scale(this->color_brightness_.value_or(x..., this->parent_->remote_values.get_color_brightness()));
|
||||||
auto range = out->range(range_from, range_to);
|
auto range = out->range(range_from, range_to);
|
||||||
|
@ -11,6 +11,9 @@ int32_t interpret_index(int32_t index, int32_t size);
|
|||||||
class AddressableLight;
|
class AddressableLight;
|
||||||
class ESPRangeIterator;
|
class ESPRangeIterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A half-open range of LEDs, inclusive of the begin index and exclusive of the end index, using zero-based numbering.
|
||||||
|
*/
|
||||||
class ESPRangeView : public ESPColorSettable {
|
class ESPRangeView : public ESPColorSettable {
|
||||||
public:
|
public:
|
||||||
ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
|
ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
|
||||||
|
Loading…
Reference in New Issue
Block a user