Skip to content

Commit 09b0ee0

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

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libraries/SD/examples/SD_time/SD_time.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
7878
Serial.print(" DIR : ");
7979
Serial.print(file.name());
8080
time_t t = file.getLastWrite();
81-
struct tm *tmstruct = localtime(&t);
81+
struct tm tmstruct;
82+
localtime_r(&t, &tmstruct);
8283
Serial.printf(
83-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
84-
tmstruct->tm_min, tmstruct->tm_sec
84+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
85+
tmstruct.tm_min, tmstruct.tm_sec
8586
);
8687
if (levels) {
8788
listDir(fs, file.path(), levels - 1);
@@ -92,10 +93,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
9293
Serial.print(" SIZE: ");
9394
Serial.print(file.size());
9495
time_t t = file.getLastWrite();
95-
struct tm *tmstruct = localtime(&t);
96+
struct tm tmstruct;
97+
localtime_r(&t, &tmstruct);
9698
Serial.printf(
97-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
98-
tmstruct->tm_min, tmstruct->tm_sec
99+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
100+
tmstruct.tm_min, tmstruct.tm_sec
99101
);
100102
}
101103
file = root.openNextFile();

0 commit comments

Comments
 (0)