Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos
@ 2019-09-12 17:44 Maria
  2019-11-06  0:44 ` [Tarantool-patches] " Alexander Turenko
  2019-12-20 22:00 ` [Tarantool-patches] [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos Vladislav Shpilevoy
  0 siblings, 2 replies; 9+ messages in thread
From: Maria @ 2019-09-12 17:44 UTC (permalink / raw)
  To: tarantool-patches; +Cc: alexander.turenko, Maria

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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-12-24 16:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12 17:44 [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos Maria
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox