From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 F0404469719 for ; Tue, 11 Feb 2020 15:36:59 +0300 (MSK) Date: Tue, 11 Feb 2020 15:36:58 +0300 From: Nikita Pettik Message-ID: <20200211123658.GA5168@tarantool.org> References: <20200210075707.86953-1-arkholga@tarantool.org> <20200210130823.GF1110@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH] json: fix silent change of global json settings List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Olga Arkhangelskaia Cc: tarantool-patches@dev.tarantool.org On 11 Feb 11:46, Olga Arkhangelskaia wrote: > Hi Nikita! Thanks for the review! > > I fixed all issues that you have pointed out. > > And pushed branch. LGTM > 10.02.2020 16:08, Nikita Pettik пишет: > > On 10 Feb 10:57, Olga Arkhangelskaia wrote: > > Here is new diff > > diff --git a/third_party/lua-cjson/lua_cjson.c > b/third_party/lua-cjson/lua_cjson.c > index f855cbd80..5925e7e6f 100644 > --- a/third_party/lua-cjson/lua_cjson.c > +++ b/third_party/lua-cjson/lua_cjson.c > @@ -1005,9 +1005,18 @@ static int json_decode(lua_State *l) >                    "expected 1 or 2 arguments"); > >      struct luaL_serializer *cfg = luaL_checkserializer(l); > -    struct luaL_serializer user_cfg = *cfg; > +    struct luaL_serializer user_cfg; > +    /* > +     * user_cfg is per-call local version of global cfg: it is > +     * used if user passes custom options to :decode() method > +     * as a separate arguments. In this case it is required > +     * to avoid modifying global parameters. Life span of > +     * user_cfg is restricted by the scope of :decode() so it > +     * is enough to allocate it on the stack. > +     */ >      json.cfg = cfg; >      if (lua_gettop(l) == 2) { > +        user_cfg = *cfg; >          luaL_serializer_parse_options(l, &user_cfg); >          lua_pop(l, 1); >          json.cfg = &user_cfg; >