Skip to content

Commit e0ad3c4

Browse files
authored
robustness improvement: rewind file before writing empty JSON skeleton
prevents creating corrupted JSON if the previous file content was ``{}``, the result would be ``{"0":{}}`` if the file position is not reset first.
1 parent 72b1f59 commit e0ad3c4

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

wled00/file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ bool appendObjectToFile(const char* key, JsonDocument* content, uint32_t s, uint
226226
if (f.size() < 4) { // file uninitialized -> write minimal skeleton
227227
char init[12];
228228
strcpy_P(init, PSTR("{\"0\":{}}"));
229+
f.seek(0, SeekSet); // rewind to ensure we overwrite from the start
229230
f.print(init);
230231
}
231232

0 commit comments

Comments
 (0)