Make check in os.time() consistent.

Thanks to Temir Galeev. #1470
This commit is contained in:
Mike Pall 2026-06-25 11:59:34 +02:00
parent d2c1327f57
commit 295d45fb26

View File

@ -224,6 +224,7 @@ LJLIB_CF(os_date)
LJLIB_CF(os_time)
{
time_t t;
errno = 0;
if (lua_isnoneornil(L, 1)) { /* called without args? */
t = time(NULL); /* get current time */
} else {
@ -237,7 +238,6 @@ LJLIB_CF(os_time)
ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
ts.tm_isdst = getboolfield(L, "isdst");
errno = 0;
t = mktime(&ts);
}
if (t == (time_t)(-1) && errno != 0)