From: Maria <maria.khaydich@tarantool.org>
To: tarantool-patches@freelists.org
Cc: alexander.turenko@tarantool.org, Maria <maria.khaydich@tarantool.org>
Subject: [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos
Date: Thu, 12 Sep 2019 20:44:48 +0300 [thread overview]
Message-ID: <20190912174448.25680-1-maria.khaydich@tarantool.org> (raw)
Function decode of module msgpackffi was passing
value of type const unsigned char * to a C function
that accepts arguments of type const char *.
Closes #3926
Test added
---
src/lua/msgpackffi.lua | 8 +++++---
test/app-tap/msgpackffi.test.lua | 6 ++++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua
index f7ee44291..18a3cb3d5 100644
--- a/src/lua/msgpackffi.lua
+++ b/src/lua/msgpackffi.lua
@@ -11,6 +11,7 @@ local uint16_ptr_t = ffi.typeof('uint16_t *')
local uint32_ptr_t = ffi.typeof('uint32_t *')
local uint64_ptr_t = ffi.typeof('uint64_t *')
local const_char_ptr_t = ffi.typeof('const char *')
+local char_ptr_t = ffi.typeof('char *')
ffi.cdef([[
char *
@@ -602,11 +603,12 @@ local function decode_unchecked(str, offset)
local buf = ffi.cast(const_char_ptr_t, str)
bufp[0] = buf + offset - 1
local r = decode_r(bufp)
- return r, bufp[0] - buf + 1
- elseif ffi.istype(const_char_ptr_t, str) then
+ return r, ffi.cast(char_ptr_t, bufp[0]) - buf + 1
+ elseif ffi.istype(const_char_ptr_t, str) or
+ ffi.istype(char_ptr_t, str) then
bufp[0] = str
local r = decode_r(bufp)
- return r, bufp[0]
+ return r, ffi.cast(char_ptr_t, bufp[0])
else
error("msgpackffi.decode_unchecked(str, offset) -> res, new_offset | "..
"msgpackffi.decode_unchecked(const char *buf) -> res, new_buf")
diff --git a/test/app-tap/msgpackffi.test.lua b/test/app-tap/msgpackffi.test.lua
index f2a8f254b..3ca09b304 100755
--- a/test/app-tap/msgpackffi.test.lua
+++ b/test/app-tap/msgpackffi.test.lua
@@ -4,6 +4,7 @@ package.path = "lua/?.lua;"..package.path
local tap = require('tap')
local common = require('serializer_test')
+local buffer = require('buffer')
local function is_map(s)
local b = string.byte(string.sub(s, 1, 1))
@@ -68,6 +69,11 @@ local function test_other(test, s)
test:is(#s.encode(-0x8001), 5, "len(encode(-0x8001))")
test:is(#s.encode(-0x80000000), 5, "len(encode(-0x80000000))")
test:is(#s.encode(-0x80000001), 9, "len(encode(-0x80000001))")
+
+ -- gh-3926: decode result cannot be assigned to buffer.rpos
+ local buf = buffer.ibuf()
+ local res, buf.rpos = msgpackffi.decode(buf.rpos, buf.wpos - buf.rpos)
+ test:iscdata(buf.rpos, ‘char *’)
end
tap.test("msgpackffi", function(test)
--
2.20.1 (Apple Git-117)
next reply other threads:[~2019-09-12 17:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 17:44 Maria [this message]
2019-11-06 0:44 ` [Tarantool-patches] " Alexander Turenko
2019-11-13 11:21 ` [Tarantool-patches] [tarantool-patches] " Maria Khaydich
2019-12-08 23:36 ` Alexander Turenko
2019-12-11 11:15 ` [Tarantool-patches] [tarantool-patches] Re: [PATCH] lua: keeping the pointer type in msgpackffi.decode Maria Khaydich
2019-12-17 23:32 ` Alexander Turenko
2019-12-20 22:00 ` [Tarantool-patches] [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos Vladislav Shpilevoy
2019-12-24 10:26 ` Maria Khaydich
2019-12-24 16:26 ` Vladislav Shpilevoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190912174448.25680-1-maria.khaydich@tarantool.org \
--to=maria.khaydich@tarantool.org \
--cc=alexander.turenko@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox