Comparison

util-src/ringbuffer.c @ 10898:c6465fb3c839

util.ringbuffer: Prevent creation of zero-size buffer
author Kim Alvefur <zash@zash.se>
date Fri, 29 May 2020 18:11:42 +0200
parent 10480:94cacf9fd0ae
child 10899:8048255ae61e
comparison
equal deleted inserted replaced
10897:37df1e757f02 10898:c6465fb3c839
196 return 1; 196 return 1;
197 } 197 }
198 198
199 static int rb_new(lua_State *L) { 199 static int rb_new(lua_State *L) {
200 size_t size = luaL_optinteger(L, 1, sysconf(_SC_PAGESIZE)); 200 size_t size = luaL_optinteger(L, 1, sysconf(_SC_PAGESIZE));
201 luaL_argcheck(L, size > 0, 1, "positive integer expected");
201 ringbuffer *b = lua_newuserdata(L, sizeof(ringbuffer) + size); 202 ringbuffer *b = lua_newuserdata(L, sizeof(ringbuffer) + size);
202 203
203 b->rpos = 0; 204 b->rpos = 0;
204 b->wpos = 0; 205 b->wpos = 0;
205 b->alen = size; 206 b->alen = size;