lua-zlib icon indicating copy to clipboard operation
lua-zlib copied to clipboard

Whether a condition judgment is necessary.

Open rodman10 opened this issue 3 years ago • 3 comments

I notice the following code snippet in lz_filter_impl function:

/*  Do the actual deflate'ing: */
if (lua_gettop(L) > 0) {
    stream->next_in = (unsigned char*)lua_tolstring(L, -1, &avail_in);
} else {
    stream->next_in = NULL;
    avail_in = 0;
}

however there is always a luaL_buffinit before this, so the stack may always larger than 0 ? Thanks for explanation :)

rodman10 avatar Jul 08 '22 04:07 rodman10

The lz_filter_impl may be called from Lua with no input parameters in which case we wouldn't want to call lua_tolstring() on a non-existent stack element.

brimworks avatar Jul 08 '22 15:07 brimworks

Thanks for explanation, but if this jugement is for empty parameters, I think it should be > 1 because luaL_buffinit will always push an userdata on stack. 16573535048526 Above is an example of empty parameters, lua_tolstring returns NULL if convert failed.

rodman10 avatar Jul 09 '22 07:07 rodman10

Oh, that looks like an oversight on my part. Would you like to open a pull request to fix this?

I'm actually not actively using Lua in any of my projects right now, so motivation for me to maintain this is a bit low at this moment in time.

Thanks!

brimworks avatar Jul 16 '22 20:07 brimworks