From dcdc05b59240fd515488a62a38d5a4d55ae8e72a Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 20 Nov 2025 22:36:46 +0100 Subject: [PATCH] unicode-related robustness improvements * enable ARDUINOJSON_DECODE_UNICODE (otherwise unicode needs 6(!) bytes for encoding) * robustness: increase a few tiny string buffers for some extra margin * Web UI: allow entering up to 64 chars as segment name --- wled00/data/index.js | 2 +- wled00/file.cpp | 6 +++--- wled00/presets.cpp | 8 ++++---- wled00/wled.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wled00/data/index.js b/wled00/data/index.js index 5d08a3f8..a1b564ec 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -827,7 +827,7 @@ function populateSegments(s) (cfg.comp.segpwr ? segp : '') + `
`+ `` + // - ``+ + ``+ ``+ ``+ ``+ diff --git a/wled00/file.cpp b/wled00/file.cpp index 5a82bdb3..bb853df9 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -214,7 +214,7 @@ bool appendObjectToFile(const char* key, JsonDocument* content, uint32_t s, uint if (!f) return false; if (f.size() < 3) { - char init[10]; + char init[12]; strcpy_P(init, PSTR("{\"0\":{}}")); f.print(init); } @@ -285,7 +285,7 @@ bool appendObjectToFile(const char* key, JsonDocument* content, uint32_t s, uint bool writeObjectToFileUsingId(const char* file, uint16_t id, JsonDocument* content) { - char objKey[10]; + char objKey[12]; sprintf(objKey, "\"%d\":", id); return writeObjectToFile(file, objKey, content); } @@ -360,7 +360,7 @@ bool writeObjectToFile(const char* file, const char* key, JsonDocument* content) bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest) { - char objKey[10]; + char objKey[12]; sprintf(objKey, "\"%d\":", id); return readObjectFromFile(file, objKey, dest); } diff --git a/wled00/presets.cpp b/wled00/presets.cpp index 3e5b4142..b8d121d0 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -12,7 +12,7 @@ static volatile byte presetToApply = 0; static volatile byte callModeToApply = 0; static volatile byte presetToSave = 0; static volatile int8_t saveLedmap = -1; -static char quickLoad[9]; +static char quickLoad[12]; // WLEDMM 9->12 to prevent crashing with unicode static char saveName[33]; static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false; @@ -88,8 +88,8 @@ static void doSaveState() { // clean up saveLedmap = -1; presetToSave = 0; - saveName[0] = '\0'; - quickLoad[0] = '\0'; + memset(saveName, '\0', sizeof(saveName)); + memset(quickLoad,'\0', sizeof(quickLoad)); playlistSave = false; } @@ -306,7 +306,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj) presetToSave = index; playlistSave = false; - if (sObj[F("ql")].is()) strlcpy(quickLoad, sObj[F("ql")].as(), 9); // client limits QL to 2 chars, buffer for 8 bytes to allow unicode + if (sObj[F("ql")].is()) strlcpy(quickLoad, sObj[F("ql")].as(), sizeof(quickLoad)); // client limits QL to 2 chars, buffer for 12 bytes to allow encoded unicode if (sObj.size()==0 || sObj["o"].isNull()) { // no "o" means not a playlist or custom API call, saving of state is async (not immediately) includeBri = sObj["ib"].as() || sObj.size()==0 || index==255; // temporary preset needs brightness diff --git a/wled00/wled.h b/wled00/wled.h index 138157a7..1de5d8fd 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -176,7 +176,7 @@ #include "src/dependencies/async-mqtt-client/AsyncMqttClient.h" #endif -#define ARDUINOJSON_DECODE_UNICODE 0 +#define ARDUINOJSON_DECODE_UNICODE 1 // WLEDMM enable unicode support -> prevents crashes when user enters unicode strings in webUI #include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/ArduinoJson-v6.h"
${isMSeg?'Start X':'Start LED'}