Skip to content

Commit 9f39936

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

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
8383
Serial.print(" DIR : ");
8484
Serial.print(file.name());
8585
time_t t = file.getLastWrite();
86-
struct tm *tmstruct = localtime(&t);
86+
struct tm tmstruct;
87+
localtime_r(&t, &tmstruct);
8788
Serial.printf(
88-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
89-
tmstruct->tm_min, tmstruct->tm_sec
89+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
90+
tmstruct.tm_min, tmstruct.tm_sec
9091
);
9192
if (levels) {
9293
listDir(fs, file.path(), levels - 1);
@@ -97,10 +98,11 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
9798
Serial.print(" SIZE: ");
9899
Serial.print(file.size());
99100
time_t t = file.getLastWrite();
100-
struct tm *tmstruct = localtime(&t);
101+
struct tm tmstruct;
102+
localtime_r(&t, &tmstruct);
101103
Serial.printf(
102-
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour,
103-
tmstruct->tm_min, tmstruct->tm_sec
104+
" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour,
105+
tmstruct.tm_min, tmstruct.tm_sec
104106
);
105107
}
106108
file = root.openNextFile();

0 commit comments

Comments
 (0)