Fix corner case of os.time().

Thanks to Temir Galeev. #1470
This commit is contained in:
Mike Pall 2026-06-13 10:59:29 +02:00
parent c3b379bf50
commit 72d2061ae2

View File

@ -237,9 +237,10 @@ LJLIB_CF(os_time)
ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u); ts.tm_mon = (int)((unsigned int)getfield(L, "month", -1) - 1u);
ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u); ts.tm_year = (int)((unsigned int)getfield(L, "year", -1) - 1900u);
ts.tm_isdst = getboolfield(L, "isdst"); ts.tm_isdst = getboolfield(L, "isdst");
errno = 0;
t = mktime(&ts); t = mktime(&ts);
} }
if (t == (time_t)(-1)) if (t == (time_t)(-1) && errno != 0)
lua_pushnil(L); lua_pushnil(L);
else else
lua_pushnumber(L, (lua_Number)t); lua_pushnumber(L, (lua_Number)t);