robustness improvements
* handling of stop = 0 when calculating sizes (avoid unsigned underflow) * make sure groupLength() is never zero (to avoid div/0) * gapmaps: check for "(gapSize > 0)" added. not sure if all the checks are 100% needed, but they will improve robustness in corner cases.
This commit is contained in:
@@ -540,7 +540,7 @@ typedef struct Segment {
|
||||
inline uint16_t width(void) const { return (stop > start) ? (stop - start) : 0; } // segment width in physical pixels (length if 1D)
|
||||
inline uint16_t height(void) const { return (stopY > startY) ? (stopY - startY) : 0; } // segment height (if 2D) in physical pixels // WLEDMM make sure its always > 0
|
||||
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels
|
||||
inline uint16_t groupLength(void) const { return grouping + spacing; }
|
||||
inline uint16_t groupLength(void) const { return max(1, grouping + spacing); } // WLEDMM length = 0 could lead to div/0 in virtualWidth() and virtualHeight()
|
||||
inline uint8_t getLightCapabilities(void) const { return _capabilities; }
|
||||
|
||||
static size_t getUsedSegmentData(void) { return _usedSegmentData; } // WLEDMM size_t
|
||||
@@ -628,6 +628,7 @@ typedef struct Segment {
|
||||
inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed
|
||||
uint_fast16_t width = virtualWidth(); // segment width in logical pixels
|
||||
uint_fast16_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;
|
||||
}
|
||||
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
|
||||
|
||||
@@ -115,7 +115,7 @@ void WS2812FX::setUpMatrix() {
|
||||
// 1 ... active pixel (it will count and will be mapped)
|
||||
JsonArray map = doc.as<JsonArray>();
|
||||
gapSize = map.size();
|
||||
if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map
|
||||
if (!map.isNull() && (gapSize > 0) && gapSize >= customMappingSize) { // not an empty map //softhack also check gapSize>0
|
||||
gapTable = new int8_t[gapSize];
|
||||
if (gapTable) for (size_t i = 0; i < gapSize; i++) {
|
||||
gapTable[i] = constrain(map[i], -1, 1);
|
||||
|
||||
@@ -1050,7 +1050,7 @@ uint32_t Segment::getPixelColor(int i)
|
||||
i += start;
|
||||
/* offset/phase */
|
||||
i += offset;
|
||||
if (i >= stop) i -= length();
|
||||
if ((i >= stop) && (stop>0)) i -= length(); // WLEDMM avoid negative index (stop = 0 is a possible value)
|
||||
return strip.getPixelColor(i);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
|
||||
uint16_t start = elem["start"] | seg.start;
|
||||
if (stop < 0) {
|
||||
uint16_t len = elem["len"];
|
||||
int len = elem["len"]; // WLEDMM bugfix for broken presets with len < 0
|
||||
stop = (len > 0) ? start + len : seg.stop;
|
||||
}
|
||||
// 2D segments
|
||||
@@ -113,7 +113,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
elem.remove("id"); // remove for recursive call
|
||||
elem.remove("rpt"); // remove for recursive call
|
||||
elem.remove("n"); // remove for recursive call
|
||||
uint16_t len = stop - start;
|
||||
uint16_t len = (stop >= start) ? (stop - start) : 0; // WLEDMM stop < 1 is allowed, so we need to avoid underflow
|
||||
for (size_t i=id+1; i<strip.getMaxSegments(); i++) {
|
||||
start = start + len;
|
||||
if (start >= strip.getLengthTotal()) break;
|
||||
@@ -592,7 +592,7 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
|
||||
root[F("stopY")] = seg.stopY;
|
||||
}
|
||||
}
|
||||
if (!forPreset) root["len"] = seg.stop - seg.start;
|
||||
if (!forPreset) root["len"] = (seg.stop >= seg.start) ? (seg.stop - seg.start) : 0; // WLEDMM correct handling for stop=0
|
||||
root["grp"] = seg.grouping;
|
||||
root[F("spc")] = seg.spacing;
|
||||
root[F("of")] = seg.offset;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2306210
|
||||
#define VERSION 2306211
|
||||
|
||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||
//#define WLED_USE_MY_CONFIG
|
||||
|
||||
Reference in New Issue
Block a user