Skip to content

Commit 12f6fbc

Browse files
authored
robustness: Rewind file pointer before writing initial data
if the presets.json file initially contains ``{}`` (valid JSON, could be created by user edit), we need to first rewind the file. Otherwise the result would be ``{}{"0":{}}`` (ivalid JSON)
1 parent c819814 commit 12f6fbc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

wled00/file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static bool appendObjectToFile(const char* key, const JsonDocument* content, uin
188188
if (f.size() < 3) {
189189
char init[10];
190190
strcpy_P(init, PSTR("{\"0\":{}}"));
191+
f.seek(0, SeekSet); // rewind to ensure we overwrite from the start, instead of appending
191192
f.print(init);
192193
}
193194

0 commit comments

Comments
 (0)