Skip to content

Commit cc6ad67

Browse files
authored
Modify DateTime constructor for localtime safety
1 parent c52b1a7 commit cc6ad67

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/cppcore/Common/DateTime.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ struct DateTime {
4545
DateTime() {
4646
time_t timestamp = ::time(nullptr);
4747
tm dt{};
48-
dt = *::localtime(&timestamp);
49-
year = dt.tm_year + 1900;
48+
#if defined(_WIN32)
49+
::localtime_s(&dt, &timestamp);
50+
+#else
51+
::localtime_r(&timestamp, &dt);
52+
+#endif year = dt.tm_year + 1900;
5053
month = dt.tm_mon;
5154
day = dt.tm_mday;
5255
hour = dt.tm_hour;

0 commit comments

Comments
 (0)