From c4f9542509fb13fe8a8d586ffe7c6e022bc1b2e4 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 29 Nov 2023 02:07:33 +0100 Subject: [PATCH] Limit `system.{sleep,wait_event}` to timeouts >= 0 (#1666) Otherwise we might wait forever by mistake. --- src/api/system.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/system.c b/src/api/system.c index 51978018..2774a97a 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -386,6 +386,7 @@ static int f_wait_event(lua_State *L) { int nargs = lua_gettop(L); if (nargs >= 1) { double n = luaL_checknumber(L, 1); + if (n < 0) n = 0; lua_pushboolean(L, SDL_WaitEventTimeout(NULL, n * 1000)); } else { lua_pushboolean(L, SDL_WaitEvent(NULL)); @@ -861,6 +862,7 @@ static int f_get_time(lua_State *L) { static int f_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); + if (n < 0) n = 0; SDL_Delay(n * 1000); return 0; }