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 5709D6EC56; Sat, 20 Mar 2021 03:44:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5709D6EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616201064; bh=lfiAW1hlc6UmgO4ke/HAIhxF5zJDQsKdmN9RNY/YnoI=; 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=IW39AOgHqRpjhrwqfZvetkIrqOpxlptlZURJWa1uA1tg+YzjIuWjRJmtN39HOwBqj f0OcBbAH7xNG69hSeOBRa89hlk2nPiBV8J0ujGDyRMGPJPfyRYs9gL4od18E4vNPm6 OnE9/wxyJoalJGsyfBVeX8qw2IB3JF//YEidl0/w= 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 dev.tarantool.org (Postfix) with ESMTPS id D297C6F3CA for ; Sat, 20 Mar 2021 03:42:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D297C6F3CA Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lNPhb-00076U-V6; Sat, 20 Mar 2021 03:42:52 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sat, 20 Mar 2021 01:42:34 +0100 Message-Id: <671d2ad3ab5faac33c8f9f6eaef9d7fa79240599.1616200860.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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1C82687294EF6886B62CC997B0B8C95C4182A05F538085040872860F309B727B3A48A473478DE59DE9CD195AAAB954ED5309CF4FD4AAEABBD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE781307CBDB76B677BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375CE37341384B0BBF8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C81A23F326053F8277770F9C6C67336FCC4DA9B8D0972E5CCA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7ABB305BD10C6E5099FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C353FA85A707D24CADCC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC9149C560DC76099D75ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E7353650B6F8DE40EA5FC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0FECB2555BB02FD5A93B503F486389A921A5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20BD3311767B7455A33D986026CEC864258 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C81A23F326053F8277770F9C6C67336FCC4DA9B8D0972E5CC9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342B8615F5CFAD9D02A46FE0EBFC36899F55E10D671DD6D0C82FCF6C819B00535C6A73778967F441791D7E09C32AA3244C2BE0951B69702316103858B9998D9073CE0B41342B755BCDFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8xHC0Ak4ylbisEJfFqFVuw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822635896A928C09310A885035F24BD0FFF3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 12/16] 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 --- src/box/lua/space.cc | 6 ++---- src/lua/fiber.c | 2 +- src/lua/utf8.c | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 544a18f47..8d4d8cc23 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -568,8 +568,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); @@ -586,8 +585,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/fiber.c b/src/lua/fiber.c index edbd06ebc..02ec3d158 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -337,7 +337,7 @@ lbox_fiber_top_entry(struct fiber *f, void *cb_ctx) { struct lua_State *L = (struct lua_State *) cb_ctx; - lua_pushstring(L, tt_sprintf("%u/%s", f->fid, f->name)); + lua_pushfstring(L, "%f/%s", (lua_Number)f->fid, f->name); lua_newtable(L); diff --git a/src/lua/utf8.c b/src/lua/utf8.c index bf9bb98f4..e060fec8f 100644 --- a/src/lua/utf8.c +++ b/src/lua/utf8.c @@ -81,9 +81,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)