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