From 756317fd1ae183c4dde1202109ff6ba198a74b1a Mon Sep 17 00:00:00 2001 From: Nick Banks Date: Mon, 30 Dec 2024 11:28:01 -0600 Subject: [PATCH] Fix code scanning alert no. 213: Use of potentially dangerous function (#292) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/quicreach.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/quicreach.cpp b/src/quicreach.cpp index 4f0fd99..8183fbd 100644 --- a/src/quicreach.cpp +++ b/src/quicreach.cpp @@ -329,8 +329,13 @@ void DumpResultsToFile() { } char UtcDateTime[256]; time_t Time = time(nullptr); - struct tm* Tm = gmtime(&Time); - strftime(UtcDateTime, sizeof(UtcDateTime), "%Y.%m.%d-%H:%M:%S", Tm); + struct tm Tm; +#ifdef _WIN32 + gmtime_s(&Tm, &Time); +#else + gmtime_r(&Time, &Tm); +#endif + strftime(UtcDateTime, sizeof(UtcDateTime), "%Y.%m.%d-%H:%M:%S", &Tm); fprintf(File, "%s,%u,%u,%u,%u,%u,%u,%u,%u\n", UtcDateTime, Results.TotalCount.load(), Results.ReachableCount.load(), Results.TooMuchCount.load(), Results.MultiRttCount.load(), Results.RetryCount.load(), Results.IPv6Count.load(), Results.Quicv2Count.load(), Results.WayTooMuchCount.load());