fix(preprocessor): initialize tm structure (#96)

This commit is contained in:
Edo 2023-04-02 21:24:56 +02:00 committed by GitHub
parent 15526ab79a
commit c314990402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -83,6 +83,7 @@ private:
auto eval_expr_factor() -> i32; auto eval_expr_factor() -> i32;
auto eval_expr_unary() -> i32; auto eval_expr_unary() -> i32;
auto eval_expr_primary() -> 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_date_define(std::tm* time_p) -> void;
auto get_time_define(std::tm* time_p) -> void; auto get_time_define(std::tm* time_p) -> void;
}; };

View File

@ -40,6 +40,7 @@ preprocessor::preprocessor(context* ctx, std::string const& name, char const* da
directives_.insert({ "using_animtree", directive::USINGTREE }); directives_.insert({ "using_animtree", directive::USINGTREE });
std::tm l_time = {}; std::tm l_time = {};
get_local_time(l_time);
get_date_define(&l_time); get_date_define(&l_time);
get_time_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"); 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 auto preprocessor::get_date_define(std::tm* time_p) -> void
{ {
char buf[] = "??? ?? ????"; char buf[] = "??? ?? ????";