Software /
code /
prosody
Changeset
10953:c3b3ac63f4c3
util.ringbuffer: Ensure unsigned chars are always returned from :byte()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 24 Jun 2020 12:34:20 +0100 |
parents | 10952:05d218aae3d1 |
children | 10954:fc310727adfb |
files | spec/util_ringbuffer_spec.lua util-src/ringbuffer.c |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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; }