From d644daccedd0faea3579f291e2c43013af82b4b1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Jul 2013 00:36:34 -0700 Subject: [PATCH] Fix a potential crash in localtime_r win32. Using localtime_s anyway. Both ways it was actually threadsafe. --- Common/FileUtil.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Common/FileUtil.h b/Common/FileUtil.h index ee34c1eb1f..e11a3d40f8 100644 --- a/Common/FileUtil.h +++ b/Common/FileUtil.h @@ -29,21 +29,20 @@ // User directory indices for GetUserPath enum { - D_USER_IDX, + D_USER_IDX, D_SCREENSHOTS_IDX, - D_LOGS_IDX, + D_LOGS_IDX, D_CONFIG_IDX, - F_CONFIG_IDX, + F_CONFIG_IDX, F_MAINLOG_IDX, NUM_PATH_INDICES }; -// No thread safe #ifdef _WIN32 -inline struct tm* localtime_r (const time_t *clock, struct tm *result) { - if (!clock || !result) return NULL; - memcpy(result,localtime(clock),sizeof(*result)); - return result; +inline struct tm* localtime_r(const time_t *clock, struct tm *result) { + if (localtime_s(result, clock) == 0) + return result; + return NULL; } #endif