From 49130c9ec9a73c3ce8d39d9ddffd26699e4d27ea Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 11 Mar 2026 13:54:58 +0100 Subject: [PATCH] (chores) cleanup some compiler warnings * switch-cases that fall through * potential buffer overflow in improv.cpp * potentially uninitialized variables in FX.cpp * potential array out-of-range on segment::col[] * minor optimization: only apply gamma correction when result is needed * tag some possibly unused variables with [[maybe_unused]] --- usermods/audioreactive/audio_reactive.h | 2 +- .../usermod_v2_rotary_encoder_ui_ALT.h | 1 + wled00/FX.cpp | 4 ++-- wled00/FX.h | 11 ++++++----- wled00/FX_2Dfcn.cpp | 6 +++--- wled00/FX_fcn.cpp | 4 ++-- wled00/FXparticleSystem.cpp | 2 +- wled00/e131.cpp | 4 ++-- wled00/improv.cpp | 4 ++-- wled00/led.cpp | 2 +- wled00/util.cpp | 3 ++- wled00/wled.cpp | 4 ++-- wled00/ws.cpp | 2 +- 13 files changed, 26 insertions(+), 23 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 9a403fc9..1d5b608f 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -176,7 +176,7 @@ static bool limiterOn = false; // bool: enable / disable dynamic #else static bool limiterOn = true; #endif -static uint8_t micQuality = 0; // affects input filtering; 0 normal, 1 minimal filtering, 2 no filtering +[[maybe_unused]] static uint8_t micQuality = 0; // input filtering; 0 normal, 1 minimal filtering, 2 no filtering - unused on 8266 #ifdef FFT_USE_SLIDING_WINDOW static uint16_t attackTime = 24; // int: attack time in milliseconds. Default 0.024sec static uint16_t decayTime = 250; // int: decay time in milliseconds. New default 250ms. diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h index 255c2416..a3906e56 100644 --- a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h +++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h @@ -395,6 +395,7 @@ const char **RotaryEncoderUIUsermod::re_findModeStrings(const char json[], int n break; case ',': if (!insideQuotes) modeIndex++; + // falls through default: if (!insideQuotes) break; } diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 471f6f5f..f2ee0d4a 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -9376,9 +9376,9 @@ uint16_t mode_particlefireworks(void) { // check each rocket's state and emit particles according to its state: moving up = emit exhaust, at top = explode; falling down = standby time uint32_t emitparticles, frequency, baseangle, hueincrement; // number of particles to emit for each rocket's state // variables for circular explosions - [[maybe_unused]] int32_t speed, currentspeed, speedvariation, percircle; + [[maybe_unused]] int32_t speed = 0, currentspeed, speedvariation, percircle; int32_t counter = 0; - [[maybe_unused]] uint16_t angle; + [[maybe_unused]] uint16_t angle = 0; [[maybe_unused]] unsigned angleincrement; bool circularexplosion = false; diff --git a/wled00/FX.h b/wled00/FX.h index 1d24b885..c718c092 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -693,7 +693,7 @@ typedef struct Segment { uint8_t currentMode(uint8_t modeNew); inline uint32_t currentColor(uint8_t slot, uint32_t colorNew) const { // WLEDMM moved here from FX_fcn.cpp - return transitional && _t ? color_blend(_t->_colorT[slot], colorNew, progress(), true) : colorNew; + return transitional && _t ? color_blend(_t->_colorT[min(slot, uint8_t(2))], colorNew, progress(), true) : colorNew; // WLEDMM prevent array bounds violation - only 3 color slots allowed } CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal) const; @@ -728,25 +728,26 @@ typedef struct Segment { // WLEDMM function moved here (from FX_fcn.cpp) for better optimization by the compiler inline uint32_t __attribute__((hot)) color_from_palette(uint_fast16_t i, bool mapping, bool wrap, uint8_t mcol=0, uint8_t pbri = 255) const { - uint32_t color = gamma32(currentColor(mcol, colors[mcol])); + uint32_t color = currentColor(mcol, colors[min(mcol, uint8_t(2))]); // WLEDMM prevent array bounds violation - only 3 color slots allowed // default palette or no RGB support on segment if ((palette == 0 && mcol < NUM_COLORS) || !_isRGB) { + color = gamma32(color); if (pbri == 255) return color; - return RGBW32(scale8_video(R(color),pbri), scale8_video(G(color),pbri), scale8_video(B(color),pbri), scale8_video(W(color),pbri)); + else return RGBW32(scale8_video(R(color),pbri), scale8_video(G(color),pbri), scale8_video(B(color),pbri), scale8_video(W(color),pbri)); } uint8_t paletteIndex = i; uint_fast16_t vLen = mapping ? virtualLength() : 1; if (mapping && vLen > 1) paletteIndex = (i*255)/(vLen -1); if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end" CRGB fastled_col = ColorFromPaletteWLED(_currentPalette, paletteIndex, pbri, (strip_getPaletteBlend() == 3)? NOBLEND:LINEARBLEND); // NOTE: paletteBlend should be global - uint8_t w = W(color); // extract white channel + uint8_t w = gamma8(W(color)); // extract white channel return RGBW32(fastled_col.r, fastled_col.g, fastled_col.b, w); } // WLEDMM function moved here (from FX_fcn.cpp) for better optimization by the compiler inline uint32_t color_wheel(uint8_t pos) const { if (palette) return color_from_palette(pos, false, true, 0); - uint8_t w = W(currentColor(0, colors[0])); // extract white channel + uint8_t w = gamma8(W(currentColor(0, colors[0]))); // extract white channel pos = 255 - pos; if (pos < 85) { return RGBW32((255 - pos * 3), 0, (pos * 3), w); diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index a350a651..cd777322 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -247,7 +247,7 @@ void Segment::startFrame(void) { void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) const //WLEDMM { unsigned i = UINT_MAX; - bool sameColor = false; + [[maybe_unused]] bool sameColor = false; if (ledsrgb) { // WLEDMM small optimization i = x + y*cols; // avoid error checking done by XY() - be optimistic about ranges of x and y CRGB fastled_col = CRGB(col); @@ -304,7 +304,7 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM: if (x<0 || y<0 || x >= cols || y >= rows) return; // if pixel would fall out of virtual segment just exit unsigned i = UINT_MAX; - bool sameColor = false; + [[maybe_unused]] bool sameColor = false; if (ledsrgb) { // WLEDMM small optimization i = XY(x,y); CRGB fastled_col = CRGB(col); @@ -914,7 +914,7 @@ void Segment::drawText(const unsigned char* text, size_t maxLen, int16_t x, int1 size_t textLength = min(strnlen((char*)text, maxLen), numberOfChars); #endif // pass characters to drawCharacter() - for (int i = 0; i < textLength; i++) { + for (size_t i = 0; i < textLength; i++) { SEGMENT.drawCharacter((unsigned char) decoded_text[i], x + w*i, y, w, h, color, col2, drawShadow); } } diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index ba80d0f3..247f0fe7 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -173,8 +173,8 @@ Segment& Segment::operator= (const Segment &orig) { transitional = false; // copied segment cannot be in transition if (name) delete[] name; if (_t) delete _t; - CRGB* oldLeds = ledsrgb; - size_t oldLedsSize = ledsrgbSize; + // [[maybe_unused]] CRGB* oldLeds = ledsrgb; + // [[maybe_unused]] size_t oldLedsSize = ledsrgbSize; if (ledsrgb && !Segment::_globalLeds) d_free(ledsrgb); deallocateData(); // copy source diff --git a/wled00/FXparticleSystem.cpp b/wled00/FXparticleSystem.cpp index 877a8f20..f30b7824 100644 --- a/wled00/FXparticleSystem.cpp +++ b/wled00/FXparticleSystem.cpp @@ -1470,7 +1470,7 @@ void ParticleSystem1D::render() { // add background color uint32_t bg_color = SEGCOLOR(1); if (bg_color > 0) { //if not black - CRGB bg_color_crgb = bg_color; // convert to CRGB + [[maybe_unused]] CRGB bg_color_crgb = bg_color; // convert to CRGB for (int32_t i = 0; i <= maxXpixel; i++) { #ifdef ESP8266 // no local buffer on ESP8266 SEGMENT.addPixelColor(i, bg_color, true); diff --git a/wled00/e131.cpp b/wled00/e131.cpp index a6486ee3..bec17d47 100644 --- a/wled00/e131.cpp +++ b/wled00/e131.cpp @@ -13,7 +13,7 @@ static byte e131LastSequenceNumber[E131_MAX_UNIVERSE_COUNT] = {0}; // to detect //handles RGB data only void handleDDPPacket(e131_packet_t* p) { static bool ddpSeenPush = false; // have we seen a push yet? - int lastPushSeq = e131LastSequenceNumber[0]; + [[maybe_unused]] int lastPushSeq = e131LastSequenceNumber[0]; //reject late packets belonging to previous frame (assuming 4 packets max. before push) #if 0 // WLEDMM fixme - we definitely have more than 5-10 packets per frame !!! @@ -32,7 +32,7 @@ void handleDDPPacket(e131_packet_t* p) { uint8_t ddpChannelsPerLed = ((p->dataType & 0b00111000)>>3 == 0b011) ? 4 : 3; // data type 0x1B (formerly 0x1A) is RGBW (type 3, 8 bit/channel) // WLEDMM for debugging - static unsigned lastPush = millis(); + [[maybe_unused]] static unsigned lastPush = millis(); static unsigned packets = 0; static unsigned pixels = 0; diff --git a/wled00/improv.cpp b/wled00/improv.cpp index 7e5b3a4d..a4c31ad3 100644 --- a/wled00/improv.cpp +++ b/wled00/improv.cpp @@ -208,8 +208,8 @@ void sendImprovInfoResponse() { #endif //Use serverDescription if it has been changed from the default "WLED", else mDNS name bool useMdnsName = (strcmp(serverDescription, "WLED") == 0 && strlen(cmDNS) > 0); - char vString[32] = { '\0' }; - sprintf_P(vString, PSTR("%s/%i"), versionString, VERSION); + char vString[48] = { '\0' }; + snprintf_P(vString, 47, PSTR("%s/%i"), versionString, VERSION); const char *str[4] = {"WLED", vString, bString, useMdnsName ? cmDNS : serverDescription}; sendImprovRPCResult(ImprovRPCType::Request_Info, 4, str); diff --git a/wled00/led.cpp b/wled00/led.cpp index b058bb7f..3b9e2157 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -45,7 +45,7 @@ void applyValuesToSelectedSegs() auto pre_mode = selsegRef.mode; auto pre_col0 = selsegRef.colors[0]; auto pre_col1 = selsegRef.colors[1]; - auto pre_col2 = selsegRef.colors[2]; + // [[maybe_unused]] auto pre_col2 = selsegRef.colors[2]; for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) { Segment& seg = strip.getSegment(i); diff --git a/wled00/util.cpp b/wled00/util.cpp index a9821638..64a3822b 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -316,11 +316,12 @@ uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLe case '"': insideQuotes = !insideQuotes; break; - case '[': + case '[': // falls through case ']': break; case ',': if (!insideQuotes) qComma++; + // falls through default: if (!insideQuotes || (qComma != mode)) break; dest[printedChars++] = singleJsonSymbol; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 62fa99fc..1434c491 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1351,8 +1351,8 @@ void WLED::handleConnection() return; } - static unsigned retryCount1 = 0; // WLEDMM static unsigned retryCount = 0; // WLEDMM + [[maybe_unused]] static unsigned retryCount1 = 0; // WLEDMM #ifdef ARDUINO_ARCH_ESP32 // reconnect WiFi to clear stale allocations if heap gets too low if ((now - heapTime > 5000) && !strip.isUpdating()) { // WLEDMM: updated with better logic for small heap available by block, not total. // WLEDMM trying to use a moment when the strip is idle @@ -1510,7 +1510,7 @@ void WLED::handleConnection() void WLED::handleStatusLED() { #if defined(STATUSLED) - uint32_t c = 0; + [[maybe_unused]] uint32_t c = 0; #if STATUSLED>=0 if (pinManager.isPinAllocated(STATUSLED)) { diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 8bdd7faa..308a90c1 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -290,7 +290,7 @@ static bool sendLiveLedsWs(uint32_t wsClient) // WLEDMM added "static" #endif (void) unGamma8(127); // WLEDMM dummy call, just to make sure that gammaTinv is initialized, so we can use fast_unGamma8 - uint8_t stripBrightness = strip.getBrightness(); + // [[maybe_unused]] uint8_t stripBrightness = strip.getBrightness(); for (size_t i = 0; pos < bufSize -2; i += n) { //WLEDMM skipping lines done right