mirror of
https://github.com/bjc/prosody.git
synced 2025-04-05 06:07:37 +03:00
util.ringbuffer: Ensure unsigned chars are always returned from :byte()
This commit is contained in:
parent
f7614d491a
commit
b9a670dace
2 changed files with 10 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue