Skip to content

Commit d9e6915

Browse files
Potential fix for code scanning alert no. 79: Use of potentially dangerous function
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 57a7b30 commit d9e6915

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
2828
Serial.print(" DIR : ");
2929
Serial.print(file.name());
3030
time_t t = file.getLastWrite();
31-
struct tm *tmstruct = localtime(&t);
31+
struct tm tmstruct;
32+
localtime_r(&t, &tmstruct);
3233
Serial.printf(
33-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
34-
tmstruct->tm_min, tmstruct->tm_sec
34+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
35+
tmstruct.tm_min, tmstruct.tm_sec
3536
);
3637
if (levels) {
3738
listDir(fs, file.path(), levels - 1);
@@ -42,10 +43,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
4243
Serial.print(" SIZE: ");
4344
Serial.print(file.size());
4445
time_t t = file.getLastWrite();
45-
struct tm *tmstruct = localtime(&t);
46+
struct tm tmstruct;
47+
localtime_r(&t, &tmstruct);
4648
Serial.printf(
47-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
48-
tmstruct->tm_min, tmstruct->tm_sec
49+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
50+
tmstruct.tm_min, tmstruct.tm_sec
4951
);
5052
}
5153
file = root.openNextFile();

0 commit comments

Comments
 (0)