From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 625F26FC8F; Thu, 25 Mar 2021 00:26:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 625F26FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616621169; bh=u07D+ExcMCuXHFAo8dNTJtOH7+MiHZrPXlCx3jtGf4g=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=x3f5aQevgLeuo+HavwmBpYKyHov4gCJSPmduO/2RslFjNc9zrdXXky/Zev+gUq+UN VENZcFkDY4WHcTIIz0LOkqMcLSiyNd8WdrH2kdTcXIrMFPKTMKMw/iCKrowB2Y8wkz iysgtMr+TEJMo9i/ACW/eLRi8vPhMFOgER5HgRbI= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1AF7F6FFC4 for ; Thu, 25 Mar 2021 00:24:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1AF7F6FFC4 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1lPAzX-0004ib-4f; Thu, 25 Mar 2021 00:24:39 +0300 To: tarantool-patches@dev.tarantool.org, kyukhin@tarantool.org Date: Wed, 24 Mar 2021 22:24:23 +0100 Message-Id: <1fffad7430a9a709921c8a0900a77f2cd10e2d45.1616620860.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9064ADF4728AA0EE954173BE606B1EB548800CB16E8E806CE182A05F538085040450CDD58D13736BA63C047FF5D4BA32CAB8E1E59E203FC7EF9E4F58C4E49F590 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A4C4638C9DDF45FCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372CAA106849E7D531EA1F7E6F0F101C67CDEEF6D7F21E0D1D174C73DBBBFC76641763F9D2EFCE7A1A8A88AF5697E6C48CFD5D49F5D3BDE0F4389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0DEC8C2C8BCD2534D8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6A70DDFFB3186CBC5CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249CA7DD71A7B3575AE76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BDAAF80516FC4B78B3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B091A620F70A64A45A99449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C33D321E7403792E343D7D993A0B92D134F5D81C698A659EA775ECD9A6C639B01BC09775C1D3CA48CFC9BE88FFEDFA497A35872C767BF85DA22EF20D2F80756B5F40A5AABA2AD3711975ECD9A6C639B01B78DA827A17800CE74ABCC139FF3F849B731C566533BA786A40A5AABA2AD371193C9F3DD0FB1AF5EB417FD7EC7EC0BD913C9F3DD0FB1AF5EB4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824AC8B6CDF511875BC4E8F7B195E1C97831148145A0506FFD489BB839037DF3A6B5 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C5DD32608FC869F5D9D572D64D5B70D32F18372524412951A9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EB7BD66E9101C10057415E5D10C9A2721A9427134AF76314AC58FC611973E1733F2BDD2057F17C0C1D7E09C32AA3244C15C3A1F0FDA1B270904F593561D287DA1DD47778AE04E04D729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjqzNotmU+geX/asO7911WA== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110A906815429F9D9609F4DCA58200BC739070E915D5AA3DB4C07784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 11/15] lua: use lua_pushfstring() instead of tt_sprintf() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" In a few places to push a formatted string was used 2 calls: tt_sprintf() + lua_pushstring(). It wasn't necessary because Lua API has lua_pushfstring() with a big enough subset of printf format features. But more importantly - it was a bug. lua_pushstring() is a GC point. Before copying the passed string it tries to invoke Lua GC, which might invoke a __gc handler for some cdata, where static alloc might be used, and it can rewrite the string passed to lua_pushstring() in the beginning of the stack. Part of #5632 (cherry picked from commit b3872a38b1e4be6a84d0621c833a196baf70284f) --- src/box/lua/space.cc | 6 ++---- src/lua/utf8.c | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 9ea0d6f7e..962796e6a 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -480,8 +480,7 @@ lbox_space_frommap(struct lua_State *L) space = space_by_id(id); if (space == NULL) { lua_pushnil(L); - lua_pushstring(L, tt_sprintf("Space with id '%d' "\ - "doesn't exist", id)); + lua_pushfstring(L, "Space with id '%d' doesn't exist", id); return 2; } assert(space->format != NULL); @@ -498,8 +497,7 @@ lbox_space_frommap(struct lua_State *L) if (tuple_fieldno_by_name(dict, key, key_len, key_hash, &fieldno)) { lua_pushnil(L); - lua_pushstring(L, tt_sprintf("Unknown field '%s'", - key)); + lua_pushfstring(L, "Unknown field '%s'", key); return 2; } lua_rawseti(L, -3, fieldno+1); diff --git a/src/lua/utf8.c b/src/lua/utf8.c index 0d9c49a8b..53cdcb023 100644 --- a/src/lua/utf8.c +++ b/src/lua/utf8.c @@ -83,9 +83,8 @@ utf8_str_to_case(struct lua_State *L, const char *src, int src_bsize, } else { cord_ibuf_put(ibuf); lua_pushnil(L); - lua_pushstring(L, tt_sprintf("error during ICU case "\ - "transform: %s", - u_errorName(err))); + lua_pushfstring(L, "error during ICU case " + "transform: %s", u_errorName(err)); return 2; } /* -- 2.24.3 (Apple Git-128)