From d3690ff0060f0856b528562d94986382913922db Mon Sep 17 00:00:00 2001 From: Edo Date: Sun, 2 Apr 2023 21:24:56 +0200 Subject: [PATCH] fix(preprocessor): initialize tm structure (#96) --- include/xsk/gsc/preprocessor.hpp | 1 + src/gsc/preprocessor.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/xsk/gsc/preprocessor.hpp b/include/xsk/gsc/preprocessor.hpp index 63703242..1a4fa8e2 100644 --- a/include/xsk/gsc/preprocessor.hpp +++ b/include/xsk/gsc/preprocessor.hpp @@ -83,6 +83,7 @@ private: auto eval_expr_factor() -> i32; auto eval_expr_unary() -> i32; auto eval_expr_primary() -> i32; + auto get_local_time(std::tm& ltime) -> void; auto get_date_define(std::tm* time_p) -> void; auto get_time_define(std::tm* time_p) -> void; }; diff --git a/src/gsc/preprocessor.cpp b/src/gsc/preprocessor.cpp index 7cf91940..a47953aa 100644 --- a/src/gsc/preprocessor.cpp +++ b/src/gsc/preprocessor.cpp @@ -40,6 +40,7 @@ preprocessor::preprocessor(context* ctx, std::string const& name, char const* da directives_.insert({ "using_animtree", directive::USINGTREE }); std::tm l_time = {}; + get_local_time(l_time); get_date_define(&l_time); get_time_define(&l_time); } @@ -1357,6 +1358,17 @@ auto preprocessor::eval_expr_primary() -> i32 throw ppr_error(eval_peek().pos, "invalid preprocessor expression"); } +auto preprocessor::get_local_time(std::tm& l_time) -> void +{ + std::time_t t; + time(&t); +#ifndef _WIN32 + localtime_r(&t, &l_time); +#else + localtime_s(&l_time, &t); +#endif +} + auto preprocessor::get_date_define(std::tm* time_p) -> void { char buf[] = "??? ?? ????";