refactor: use localtime_r(...) for thread safety

This commit is contained in:
Yurii
2026-05-17 04:46:47 +03:00
parent af2d4624b3
commit 9c2e420ec7
+6 -2
View File
@@ -810,9 +810,13 @@ protected:
static void getFilename(char* filename, size_t maxSizeFilename, const char* type) { static void getFilename(char* filename, size_t maxSizeFilename, const char* type) {
const time_t now = time(nullptr); const time_t now = time(nullptr);
const tm* localNow = localtime(&now);
tm localNow {};
localtime_r(&now, &localNow);
char localNowValue[20]; char localNowValue[20];
strftime(localNowValue, sizeof(localNowValue), PSTR("%Y-%m-%d-%H-%M-%S"), localNow); strftime(localNowValue, sizeof(localNowValue), PSTR("%Y-%m-%d-%H-%M-%S"), &localNow);
snprintf_P(filename, maxSizeFilename, PSTR("%s_%s_%s.json"), networkSettings.hostname, localNowValue, type); snprintf_P(filename, maxSizeFilename, PSTR("%s_%s_%s.json"), networkSettings.hostname, localNowValue, type);
} }
}; };