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.
This commit is contained in:
Frank Möhle
2026-04-05 22:01:33 +02:00
committed by GitHub
parent 72b1f59e42
commit e0ad3c4638

View File

@@ -226,6 +226,7 @@ bool appendObjectToFile(const char* key, JsonDocument* content, uint32_t s, uint
if (f.size() < 4) { // file uninitialized -> write minimal skeleton if (f.size() < 4) { // file uninitialized -> write minimal skeleton
char init[12]; char init[12];
strcpy_P(init, PSTR("{\"0\":{}}")); strcpy_P(init, PSTR("{\"0\":{}}"));
f.seek(0, SeekSet); // rewind to ensure we overwrite from the start
f.print(init); f.print(init);
} }