# HG changeset patch # User Matthew Wild # Date 1592998460 -3600 # Node ID c3b3ac63f4c327e4d5dd0f1ef1cbb2cd4409733e # Parent 05d218aae3d13b7fd09691786db374ee69b7be3d util.ringbuffer: Ensure unsigned chars are always returned from :byte() diff -r 05d218aae3d1 -r c3b3ac63f4c3 spec/util_ringbuffer_spec.lua --- a/spec/util_ringbuffer_spec.lua Tue Jun 23 17:59:24 2020 +0200 +++ b/spec/util_ringbuffer_spec.lua Wed Jun 24 12:34:20 2020 +0100 @@ -92,5 +92,12 @@ end end end); + + it("works with characters > 127", function () + local b = rb.new(); + b:write(string.char(0, 140)); + local r = { b:byte(1, 2) }; + assert.same({ 0, 140 }, r); + end); end); end); diff -r 05d218aae3d1 -r c3b3ac63f4c3 util-src/ringbuffer.c --- a/util-src/ringbuffer.c Tue Jun 23 17:59:24 2020 +0200 +++ b/util-src/ringbuffer.c Wed Jun 24 12:34:20 2020 +0100 @@ -262,15 +262,15 @@ if(calc_splice_positions(b, start, end, &wrapped_start, &wrapped_end)) { if(wrapped_end <= wrapped_start) { for(i = wrapped_start; i < (long)b->alen; i++) { - lua_pushinteger(L, b->buffer[i]); + lua_pushinteger(L, (unsigned char)b->buffer[i]); } for(i = 0; i < wrapped_end; i++) { - lua_pushinteger(L, b->buffer[i]); + lua_pushinteger(L, (unsigned char)b->buffer[i]); } return wrapped_end + (b->alen - wrapped_start); } else { for(i = wrapped_start; i < wrapped_end; i++) { - lua_pushinteger(L, b->buffer[i]); + lua_pushinteger(L, (unsigned char)b->buffer[i]); } return wrapped_end - wrapped_start; }