From 34252fb10ad4038cf6bf713f4f4d1c21ee948812 Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Mon, 26 Apr 2021 08:37:09 -0300 Subject: [PATCH] Set parameter 2 and 3 to none before luaL_buffinit() --- src/luasocket/buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/luasocket/buffer.c b/src/luasocket/buffer.c index 5ea97a9..e1ae981 100644 --- a/src/luasocket/buffer.c +++ b/src/luasocket/buffer.c @@ -107,10 +107,16 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { * object:receive() interface \*-------------------------------------------------------------------------*/ int buffer_meth_receive(lua_State *L, p_buffer buf) { - int err = IO_DONE, top = lua_gettop(L); luaL_Buffer b; size_t size; - const char *part = luaL_optlstring(L, 3, "", &size); + const char *part; + int err = IO_DONE; + int top = lua_gettop(L); + if (top < 3) { + lua_settop(L, 3); + top = 3; + } + part = luaL_optlstring(L, 3, "", &size); #ifdef LUASOCKET_DEBUG p_timeout tm = timeout_markstart(buf->tm); #endif