From 9e46d46dd5d13931b6a3fa1023f21a2c63a86410 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 27 Jul 2023 13:38:02 +0200 Subject: [PATCH] Changed GuiOrphanedDataCleanup to using a safer localtime function --- es-app/src/guis/GuiOrphanedDataCleanup.cpp | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiOrphanedDataCleanup.cpp b/es-app/src/guis/GuiOrphanedDataCleanup.cpp index 4fdee2675..7947f027a 100644 --- a/es-app/src/guis/GuiOrphanedDataCleanup.cpp +++ b/es-app/src/guis/GuiOrphanedDataCleanup.cpp @@ -327,8 +327,14 @@ void GuiOrphanedDataCleanup::cleanupMediaFiles() int systemProcessedCount {0}; if (cleanupFiles.size() > 0) { + struct tm tm; std::string dateString(20, '\0'); - std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime(¤tTime)); +#if defined(_WIN64) + localtime_s(&tm, ¤tTime); + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", &tm); +#else + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime_r(¤tTime, &tm)); +#endif dateString.erase(dateString.find('\0')); const std::string targetDirectory {mMediaDirectory + "CLEANUP/" + dateString + "/"}; @@ -549,8 +555,14 @@ void GuiOrphanedDataCleanup::cleanupGamelists() } if (removeCount > 0) { + struct tm tm; std::string dateString(20, '\0'); - std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime(¤tTime)); +#if defined(_WIN64) + localtime_s(&tm, ¤tTime); + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", &tm); +#else + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime_r(¤tTime, &tm)); +#endif dateString.erase(dateString.find('\0')); const std::string targetDirectory { Utils::FileSystem::getParent( @@ -733,8 +745,14 @@ void GuiOrphanedDataCleanup::cleanupCollections() } if (removeCount > 0) { + struct tm tm; std::string dateString(20, '\0'); - std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime(¤tTime)); +#if defined(_WIN64) + localtime_s(&tm, ¤tTime); + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", &tm); +#else + std::strftime(&dateString[0], 20, "%Y-%m-%d_%H%M%S", localtime_r(¤tTime, &tm)); +#endif dateString.erase(dateString.find('\0')); const std::string targetDirectory {Utils::FileSystem::getParent(collectionFile) + "/CLEANUP/" + dateString + "/"};