From c06feccf2aaeba0f1a3d2d38b2ab7b08ad151197 Mon Sep 17 00:00:00 2001 From: "Bhardwaj, Gopesh" Date: Fri, 21 Mar 2025 14:21:49 +0530 Subject: [PATCH] Potential fix for code scanning alert no. 24: Use of potentially dangerous function (#220) * Potential fix for code scanning alert no. 24: Use of potentially dangerous function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * clang-format fix * use std::localtime_r instead of localtime. Co-authored-by: Madsen, Jonathan * localtime_r is defined in global namespace. --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Kandula, Venkateshwar reddy Co-authored-by: Madsen, Jonathan --- source/lib/output/output_key.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/lib/output/output_key.cpp b/source/lib/output/output_key.cpp index e360410ab0..e861819edd 100644 --- a/source/lib/output/output_key.cpp +++ b/source/lib/output/output_key.cpp @@ -68,7 +68,9 @@ get_local_datetime(const std::string& dt_format, std::time_t*& _dt_curr) char mbstr[strsize] = {}; memset(mbstr, '\0', sizeof(mbstr) * sizeof(char)); - if(std::strftime(mbstr, sizeof(mbstr) - 1, dt_format.c_str(), std::localtime(_dt_curr)) != 0) + struct tm tm_struct; + if(std::strftime( + mbstr, sizeof(mbstr) - 1, dt_format.c_str(), localtime_r(_dt_curr, &tm_struct)) != 0) return new std::string{mbstr}; return nullptr;