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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user