@@ -12,8 +12,10 @@ static volatile byte presetToApply = 0;
1212static volatile byte callModeToApply = 0 ;
1313static volatile byte presetToSave = 0 ;
1414static volatile int8_t saveLedmap = -1 ;
15- static char quickLoad[12 ]; // WLEDMM 9->12 to prevent crashing with unicode
16- static char saveName[33 ];
15+ #define QLOAD_BUFFER 12 // string needed for quickload // WLEDMM 9->12 to prevent crashing with unicode
16+ #define FNAME_BUFFER 32 // string needed for saveName
17+ static char quickLoad[QLOAD_BUFFER+1 ] = {' \0 ' }; // 1 extra byte for '\0'
18+ static char saveName[FNAME_BUFFER+1 ] = {' \0 ' }; // 1 extra byte for '\0'
1719static bool includeBri = true , segBounds = true , selectedOnly = false , playlistSave = false ;
1820
1921static const char *getFileName (bool persist = true ) {
@@ -305,15 +307,17 @@ void handlePresets()
305307void savePreset (byte index, const char * pname, JsonObject sObj )
306308{
307309 if (index == 0 || (index > 250 && index < 255 )) return ;
308- if (pname) strlcpy (saveName, pname, 33 );
310+ if (pname) strlcpy (saveName, pname, FNAME_BUFFER+ 1 );
309311 else {
310- if (sObj [" n" ].is <const char *>()) strlcpy (saveName, sObj [" n" ].as <const char *>(), 33 );
312+ if (sObj [" n" ].is <const char *>()) strlcpy (saveName, sObj [" n" ].as <const char *>(), FNAME_BUFFER+ 1 );
311313 else sprintf_P (saveName, PSTR (" Preset %d" ), index);
312314 }
313315
314316 DEBUG_PRINT (F (" Saving preset (" )); DEBUG_PRINT (index); DEBUG_PRINT (F (" ) " )); DEBUG_PRINTLN (saveName);
315317 auto oldpresetToSave = presetToSave; // for recovery in case that esp32SemTake(presetFileMux) fails
316318 auto oldplaylistSave = playlistSave;
319+ char oldQuickLoad[QLOAD_BUFFER+1 ];
320+ strlcpy (oldQuickLoad, quickLoad, sizeof (oldQuickLoad));
317321
318322 presetToSave = index;
319323 playlistSave = false ;
@@ -334,6 +338,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
334338 USER_PRINTLN (F (" savePreset(): preset file busy, cannot write" ));
335339 presetToSave = oldpresetToSave;
336340 playlistSave = oldplaylistSave;
341+ strlcpy (quickLoad, oldQuickLoad, sizeof (quickLoad));
337342 return ; // early exit, no change
338343 }
339344
@@ -342,6 +347,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
342347 esp32SemGive (presetFileMux); // Release file mutex
343348 presetToSave = oldpresetToSave; // bugfix: restore previous state on error exit
344349 playlistSave = oldplaylistSave;
350+ strlcpy (quickLoad, oldQuickLoad, sizeof (quickLoad));
345351 return ; // cannot save API calls to temporary preset (255)
346352 }
347353 sObj .remove (" o" );
0 commit comments