1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-20 02:07:40 +00:00

Address some issues found in lgtm

Caught a few potentially issues with overflows, as well as use of
unsafe function localtime.
This commit is contained in:
Calvin Rose
2019-10-10 22:59:43 -05:00
parent 8ee54e887f
commit a18a251d16
7 changed files with 122 additions and 98 deletions

View File

@@ -477,13 +477,19 @@ static Janet os_date(int32_t argc, Janet *argv) {
janet_arity(argc, 0, 1);
(void) argv;
time_t t;
struct tm t_infos;
struct tm *t_info;
if (argc) {
t = (time_t) janet_getinteger64(argv, 0);
} else {
time(&t);
}
t_info = localtime(&t);
#ifdef JANET_WINDOWS
localtime_s(&t_infos, &t);
t_info = &t_infos;
#else
t_info = localtime_r(&t, &t_infos);
#endif
JanetKV *st = janet_struct_begin(9);
janet_struct_put(st, janet_ckeywordv("seconds"), janet_wrap_number(t_info->tm_sec));
janet_struct_put(st, janet_ckeywordv("minutes"), janet_wrap_number(t_info->tm_min));