Skip to content

Commit ad2d4ed

Browse files
committed
Disallow NaN intervals in LLTimers
1 parent 477ab1d commit ad2d4ed

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

VM/src/llltimers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ static int lltimers_on(lua_State *L)
126126
luaL_typeerror(L, 3, "function or callable table");
127127
lua_settop(L, 3);
128128

129-
if (seconds < 0.0)
130-
luaL_errorL(L, "timer interval must be positive or 0");
129+
if (seconds < 0.0 || std::isnan(seconds))
130+
luaL_errorL(L, "timer interval must be a positive number or 0");
131131

132132
// Get current time
133133
double current_time = sl_state->clockProvider ? sl_state->clockProvider(L) : 0.0;
@@ -182,8 +182,8 @@ static int lltimers_once(lua_State *L)
182182
luaL_typeerror(L, 3, "function or callable table");
183183
lua_settop(L, 3);
184184

185-
if (seconds < 0.0)
186-
luaL_errorL(L, "timer interval must be positive or 0");
185+
if (seconds < 0.0 || std::isnan(seconds))
186+
luaL_errorL(L, "timer interval must be a positive number or 0");
187187

188188
// Get current time
189189
double current_time = sl_state->clockProvider ? sl_state->clockProvider(L) : 0.0;

tests/conformance/lltimers.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ local success, err = pcall(function()
135135
end)
136136
assert(success == false)
137137

138+
-- Test NaN interval
139+
assert_errors(function() LLTimers:every(0/0, function() end) end, "timer interval must be a positive number or 0")
140+
assert_errors(function() LLTimers:once(0/0, function() end) end, "timer interval must be a positive number or 0")
141+
138142
-- Test zero interval (0 means "ASAP" and is valid)
139143
timer1_count = 0
140144
local function zero_interval_handler()

0 commit comments

Comments
 (0)