From: Vladimír Čunát Date: Wed, 30 Jan 2019 15:37:59 +0000 (+0100) Subject: treewide: avoid lua_tonumber where integer is expected X-Git-Tag: v4.0.0~38^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b73673aff85ecf1d736b49c55de3dc12ce3ebea;p=thirdparty%2Fknot-resolver.git treewide: avoid lua_tonumber where integer is expected --- diff --git a/daemon/bindings/cache.c b/daemon/bindings/cache.c index 1cd1e4532..79f8d2ef3 100644 --- a/daemon/bindings/cache.c +++ b/daemon/bindings/cache.c @@ -129,7 +129,7 @@ static int cache_max_ttl(lua_State *L) if (!lua_isnumber(L, 1)) lua_error_p(L, "expected 'max_ttl(number ttl)'"); uint32_t min = cache->ttl_min; - int64_t ttl = lua_tonumber(L, 1); + int64_t ttl = lua_tointeger(L, 1); if (ttl < 0 || ttl < min || ttl > UINT32_MAX) { lua_error_p(L, "max_ttl must be larger than minimum TTL, and in range <1, " @@ -151,7 +151,7 @@ static int cache_min_ttl(lua_State *L) if (!lua_isnumber(L, 1)) lua_error_p(L, "expected 'min_ttl(number ttl)'"); uint32_t max = cache->ttl_max; - int64_t ttl = lua_tonumber(L, 1); + int64_t ttl = lua_tointeger(L, 1); if (ttl < 0 || ttl > max || ttl > UINT32_MAX) { lua_error_p(L, "min_ttl must be smaller than maximum TTL, and in range <0, " @@ -174,7 +174,7 @@ static int cache_open(lua_State *L) /* Select cache storage backend */ struct engine *engine = engine_luaget(L); - lua_Number csize_lua = lua_tonumber(L, 1); + lua_Number csize_lua = lua_tointeger(L, 1); if (!(csize_lua >= 8192 && csize_lua < SIZE_MAX)) { /* min. is basically arbitrary */ lua_error_p(L, "invalid cache size specified, it must be in range <8192, " STR(SIZE_MAX) ">"); diff --git a/daemon/bindings/event.c b/daemon/bindings/event.c index 4e02333c6..c665dac64 100644 --- a/daemon/bindings/event.c +++ b/daemon/bindings/event.c @@ -104,7 +104,7 @@ static int event_after(lua_State *L) if (n < 2 || !lua_isnumber(L, 1) || !lua_isfunction(L, 2)) lua_error_p(L, "expected 'after(number timeout, function)'"); - return event_sched(L, lua_tonumber(L, 1), 0); + return event_sched(L, lua_tointeger(L, 1), 0); } static int event_recurrent(lua_State *L) @@ -114,7 +114,7 @@ static int event_recurrent(lua_State *L) if (n < 2 || !lua_isnumber(L, 1) || !lua_isfunction(L, 2)) lua_error_p(L, "expected 'recurrent(number interval, function)'"); - return event_sched(L, 0, lua_tonumber(L, 1)); + return event_sched(L, 0, lua_tointeger(L, 1)); } static int event_cancel(lua_State *L) @@ -183,7 +183,7 @@ static int event_fdwatch(lua_State *L) lua_error_p(L, "out of memory"); /* Start timer with the reference */ - int sock = lua_tonumber(L, 1); + int sock = lua_tointeger(L, 1); uv_loop_t *loop = uv_default_loop(); #if defined(__APPLE__) || defined(__FreeBSD__) /* libuv is buggy and fails to create poller for diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index 61fdb9aa9..02102bb2e 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -91,7 +91,7 @@ static inline int l_ffi_call(lua_State *L, int argc) return kr_error(EIO); } if (lua_isnumber(L, -1)) { /* Return code */ - status = lua_tonumber(L, -1); + status = lua_tointeger(L, -1); } else if (lua_isthread(L, -1)) { /* Continuations */ status = l_ffi_defer(lua_tothread(L, -1)); }