inactive segments robustness improvement

* Avoid uint16 underflow in width() and height(): stop > start is possible, and means "inactive segment".

Without these checks, it was possible that width() and height() produce VERY large values due to underflow.
This commit is contained in:
Frank
2023-07-03 15:43:47 +02:00
parent eabd6f60ef
commit 406a254523
3 changed files with 5 additions and 4 deletions

View File

@@ -191,6 +191,7 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
uint16_t /*IRAM_ATTR*/ Segment::XY(uint16_t x, uint16_t y) {
uint16_t width = virtualWidth(); // segment width in logical pixels
uint16_t height = virtualHeight(); // segment height in logical pixels
if ((width == 0) || (height == 0)) return 0; // softhack007 avoid div/0
return (x%width) + (y%height) * width;
}