Software /
code /
prosody
Comparison
util-src/ringbuffer.c @ 10899:8048255ae61e
util.ringbuffer: Prevent creation of buffer with negative size
Previously this would have been (unsigned)-1 which is a large positive
integer.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 04 Jun 2020 16:11:08 +0200 |
parent | 10898:c6465fb3c839 |
child | 10901:5e33926f4b43 |
comparison
equal
deleted
inserted
replaced
10898:c6465fb3c839 | 10899:8048255ae61e |
---|---|
195 lua_pushinteger(L, b->alen - b->blen); | 195 lua_pushinteger(L, b->alen - b->blen); |
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 lua_Integer size = luaL_optinteger(L, 1, sysconf(_SC_PAGESIZE)); |
201 luaL_argcheck(L, size > 0, 1, "positive integer expected"); | 201 luaL_argcheck(L, size > 0, 1, "positive integer expected"); |
202 ringbuffer *b = lua_newuserdata(L, sizeof(ringbuffer) + size); | 202 ringbuffer *b = lua_newuserdata(L, sizeof(ringbuffer) + size); |
203 | 203 |
204 b->rpos = 0; | 204 b->rpos = 0; |
205 b->wpos = 0; | 205 b->wpos = 0; |