Skip to content

Commit a666f07

Browse files
committed
fix off-by-one bug, remove unnecessary 16384 restriction
1 parent bd933ff commit a666f07

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

wled00/FX_fcn.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,7 @@ bool WS2812FX::deserializeMap(unsigned n) {
19971997
Segment::maxWidth = min(max(root[F("width")].as<int>(), 1), 255);
19981998
Segment::maxHeight = min(max(root[F("height")].as<int>(), 1), 255);
19991999
isMatrix = true;
2000+
DEBUG_PRINTF_P(PSTR("LED map width=%d, height=%d\n"), Segment::maxWidth, Segment::maxHeight);
20002001
}
20012002

20022003
d_free(customMappingTable);
@@ -2020,9 +2021,9 @@ bool WS2812FX::deserializeMap(unsigned n) {
20202021
} while (i < 32);
20212022
if (!foundDigit) break;
20222023
int index = atoi(number);
2023-
if (index < 0 || index > 16384) index = 0xFFFF;
2024+
if (index < 0 || index > 65535) index = 0xFFFF; // prevent integer wrap around
20242025
customMappingTable[customMappingSize++] = index;
2025-
if (customMappingSize > getLengthTotal()) break;
2026+
if (customMappingSize >= getLengthTotal()) break;
20262027
} else break; // there was nothing to read, stop
20272028
}
20282029
currentLedmap = n;
@@ -2032,7 +2033,7 @@ bool WS2812FX::deserializeMap(unsigned n) {
20322033
DEBUG_PRINT(F("Loaded ledmap:"));
20332034
for (unsigned i=0; i<customMappingSize; i++) {
20342035
if (!(i%Segment::maxWidth)) DEBUG_PRINTLN();
2035-
DEBUG_PRINTF_P(PSTR("%4d,"), customMappingTable[i]);
2036+
DEBUG_PRINTF_P(PSTR("%4d,"), customMappingTable[i] < 0xFFFFU ? customMappingTable[i] : -1);
20362037
}
20372038
DEBUG_PRINTLN();
20382039
#endif

0 commit comments

Comments
 (0)