[Tarantool-patches] [PATCH] msgpack: print mp_exp type as signed integer
Ilya Kosarev
i.kosarev at tarantool.org
Tue Sep 1 13:31:43 MSK 2020
MsgPack extension types allow applications to define
application-specific types. They consist of an 8-bit signed integer and
a byte array where the integer represents a kind of types and the byte
array represents data. Types from 0 to 127 are application-specific
types and types from -128 to -1 are reserved for predefined types.
However, extension types were printed as unsigned integers. Now it is
fixed and extension types are being printed in a correct way as signed
integers. Also the typo in word "Unsupported" was fixed. According test
case is introduced.
Closes #5016
---
Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-5016-fix-extension-decoding
Issue: https://github.com/tarantool/tarantool/issues/5016
src/box/lua/init.c | 2 +-
src/lua/msgpack.c | 2 +-
test/app-tap/msgpack.test.lua | 11 ++++++++---
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/box/lua/init.c b/src/box/lua/init.c
index cac62b958d..d0316ef867 100644
--- a/src/box/lua/init.c
+++ b/src/box/lua/init.c
@@ -431,7 +431,7 @@ luamp_decode_extension_box(struct lua_State *L, const char **data)
uint32_t len = mp_decode_extl(data, &ext_type);
if (ext_type != MP_ERROR) {
- luaL_error(L, "Unsuported MsgPack extension type: %u",
+ luaL_error(L, "Unsupported MsgPack extension type: %d",
ext_type);
return;
}
diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c
index 128cc5d2ff..4c4ada39cb 100644
--- a/src/lua/msgpack.c
+++ b/src/lua/msgpack.c
@@ -94,7 +94,7 @@ luamp_decode_extension_default(struct lua_State *L, const char **data)
{
int8_t ext_type;
mp_decode_extl(data, &ext_type);
- luaL_error(L, "msgpack.decode: unsupported extension: %u", ext_type);
+ luaL_error(L, "msgpack.decode: unsupported extension: %d", ext_type);
}
diff --git a/test/app-tap/msgpack.test.lua b/test/app-tap/msgpack.test.lua
index 2d62850fb3..3f7ca2c3e7 100755
--- a/test/app-tap/msgpack.test.lua
+++ b/test/app-tap/msgpack.test.lua
@@ -36,7 +36,7 @@ local function test_offsets(test, s)
end
local function test_misc(test, s)
- test:plan(5)
+ test:plan(8)
local ffi = require('ffi')
local buffer = require('buffer')
local buf = ffi.cast("const char *", "\x91\x01")
@@ -48,8 +48,13 @@ local function test_misc(test, s)
test:is_deeply(result, {1}, "ibuf_decode result")
test:ok(not st and e:match("null"), "null ibuf")
st, e = pcall(s.decode, "\xd4\x0f\x00")
- test:ok(not st and e:match("Unsuported MsgPack extension type: 15"),
- "unsupported extension decode")
+ test:is(e, "Unsupported MsgPack extension type: 15",
+ "decode result for \\xd4\\x0f\\x00: " .. e)
+ test:ok(not st, "unsupported extension decode")
+ st, e = pcall(s.decode, "\xd4\xfe\x00")
+ test:is(e, "Unsupported MsgPack extension type: -2",
+ "decode result for \\xd4\\xfe\\x00: " .. e)
+ test:ok(not st, "unsupported extension decode")
end
local function test_decode_array_map_header(test, s)
--
2.17.1
More information about the Tarantool-patches
mailing list