diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-06-24 12:34:20 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-06-24 12:34:20 +0100 |
commit | 512f97b32f8de0878f9a97a385f7105cd7fce5b7 (patch) | |
tree | 53952699c957a0993c80041b7c1cbdce42491cdc | |
parent | 240f8628053e0fd728c720e9bde78760b963f551 (diff) | |
download | prosody-512f97b32f8de0878f9a97a385f7105cd7fce5b7.tar.gz prosody-512f97b32f8de0878f9a97a385f7105cd7fce5b7.zip |
util.ringbuffer: Ensure unsigned chars are always returned from :byte()
-rw-r--r-- | spec/util_ringbuffer_spec.lua | 7 | ||||
-rw-r--r-- | util-src/ringbuffer.c | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 9a50fd20..5657b3f6 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -92,5 +92,12 @@ describe("util.ringbuffer", function () 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 --git a/util-src/ringbuffer.c b/util-src/ringbuffer.c index 007aa2ec..0f250c12 100644 --- a/util-src/ringbuffer.c +++ b/util-src/ringbuffer.c @@ -262,15 +262,15 @@ static int rb_byte(lua_State *L) { 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; } |