Skip to content

Commit c6bc9e8

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

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
4040
Serial.print(" DIR : ");
4141
Serial.print(file.name());
4242
time_t t = file.getLastWrite();
43-
struct tm *tmstruct = localtime(&t);
43+
struct tm tmstruct;
44+
localtime_r(&t, &tmstruct);
4445
Serial.printf(
45-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
46-
tmstruct->tm_min, tmstruct->tm_sec
46+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
47+
tmstruct.tm_min, tmstruct.tm_sec
4748
);
4849
if (levels) {
4950
listDir(fs, file.path(), levels - 1);
@@ -54,10 +55,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
5455
Serial.print(" SIZE: ");
5556
Serial.print(file.size());
5657
time_t t = file.getLastWrite();
57-
struct tm *tmstruct = localtime(&t);
58+
struct tm tmstruct;
59+
localtime_r(&t, &tmstruct);
5860
Serial.printf(
59-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
60-
tmstruct->tm_min, tmstruct->tm_sec
61+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
62+
tmstruct.tm_min, tmstruct.tm_sec
6163
);
6264
}
6365
file = root.openNextFile();

0 commit comments

Comments
 (0)