From 04a144f4c60383d8a011e1a163b5440d5bf5079c Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sat, 8 Aug 2026 09:59:22 +0100 Subject: [PATCH] Encapsulate wled_server.cpp's own runtime state as static, not global 4 WLED_GLOBAL variables were referenced only in wled_server.cpp: editHandler, messageHead, messageSub, optionType (messageHead was bundled on the same declaration line as messageSub but turned out to be just as single-file). Converted all 4 to file-local `static`. No behavior change - purely a storage-class change. Verified: esp32dev builds and links cleanly via `pio run -e esp32dev` (1,320,323 bytes flash, no warnings from either changed file). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01UtCyBD91vAYWvBzaMyQSHd --- wled00/wled.h | 5 ++--- wled00/wled_server.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wled00/wled.h b/wled00/wled.h index 9bafb49196..8771464708 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -776,8 +776,7 @@ WLED_GLOBAL byte currentPreset _INIT(0); WLED_GLOBAL byte errorFlag _INIT(0); -WLED_GLOBAL String messageHead, messageSub; -WLED_GLOBAL byte optionType; +// messageHead/messageSub/optionType are private to wled_server.cpp - see there. WLED_GLOBAL bool configNeedsWrite _INIT(false); // flag to initiate saving of config WLED_GLOBAL bool doReboot _INIT(false); // flag to initiate reboot from async handlers @@ -797,7 +796,7 @@ WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws"))); #ifndef WLED_DISABLE_HUESYNC WLED_GLOBAL AsyncClient *hueClient _INIT(NULL); #endif -WLED_GLOBAL AsyncWebHandler *editHandler _INIT(nullptr); +// editHandler is private to wled_server.cpp - see there. // udp interface objects WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp, notifier2Udp; diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 94014cd08e..7d3335b12c 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -23,6 +23,12 @@ // forward declarations static void createEditHandler(); +// Runtime state private to this file - previously WLED_GLOBAL, a leftover from +// when all state lived in one big extern block regardless of who used it. +static AsyncWebHandler *editHandler = nullptr; +static String messageHead, messageSub; +static byte optionType; + // define flash strings once (saves flash memory) static const char s_redirecting[] PROGMEM = "Redirecting...";