util.ringbuffer: Prevent creation of buffer with negative size

Previously this would have been (unsigned)-1 which is a large positive
integer.
vault/master
Kim Alvefur 6 years ago
parent 73efa2f2f1
commit 05bfe971bf
  1. 5
      spec/util_ringbuffer_spec.lua
  2. 2
      util-src/ringbuffer.c

@ -12,6 +12,11 @@ describe("util.ringbuffer", function ()
rb.new(0);
end);
end);
it("won't create a negatively sized buffer", function ()
assert.has_error(function ()
rb.new(-1);
end);
end);
end);
describe(":write", function ()
local b = rb.new();

@ -197,7 +197,7 @@ static int rb_free(lua_State *L) {
}
static int rb_new(lua_State *L) {
size_t size = luaL_optinteger(L, 1, sysconf(_SC_PAGESIZE));
lua_Integer size = luaL_optinteger(L, 1, sysconf(_SC_PAGESIZE));
luaL_argcheck(L, size > 0, 1, "positive integer expected");
ringbuffer *b = lua_newuserdata(L, sizeof(ringbuffer) + size);

Loading…
Cancel
Save