From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E04F1209E2 for ; Thu, 12 Sep 2019 13:44:52 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cuk7ketJwOWh for ; Thu, 12 Sep 2019 13:44:52 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 16A1220AC0 for ; Thu, 12 Sep 2019 13:44:51 -0400 (EDT) From: Maria Subject: [tarantool-patches] [PATCH] msgpackffi.decode can now be assigned to buf.rpos Date: Thu, 12 Sep 2019 20:44:48 +0300 Message-Id: <20190912174448.25680-1-maria.khaydich@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: alexander.turenko@tarantool.org, 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)