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 572776BD23; Tue, 13 Apr 2021 01:34:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 572776BD23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618266890; bh=JXstBXicittUJT/uUtYvcdGGuDP2BWC9LST0BC0qOVk=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fHs66q6tjD9BOKBAVNqgKS3oL52xgI2wywj0Ive+xFBvIU3GOE9j/zkWMeHST7aT2 UZgkFkFx/vDvu+SHU5W4xEn9lTH46aC1ekp2sKEo3R5/HRiW9TFuxMWG5VcYILSI5R s+OHL+4g4zS+5ylA0cOuvRpTSjf6rJkkHhTXZFTg= Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2D0BA6BD19 for ; Tue, 13 Apr 2021 01:34:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D0BA6BD19 Received: by mail-lf1-f41.google.com with SMTP id f17so16932129lfu.7 for ; Mon, 12 Apr 2021 15:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tjlzD+F/dui+P6z2jmgvWQTlsgAPLYylaYLC/bSxQoM=; b=eLBtwfYll0Ld/TLn5vK3ESf3RBrOV9+kQAZX2uutnpJxiau+Al6WIIi0Jbwa7nfUQJ NYKlj6s9KsiH45PHJg1PpK3TTP+30C8KUsYBv16xMceIDGdwt9plonMFvbkGitDmceOh TBBDpzOewpRQ24JXa5RatNf8kofRCKSa4khTCutjC9H/EMufnIMa2l19Z5goezAwke7G rnPiD106dH/ywIaCHgzANdzeybP7EhFPNVPsAzhgrUfvLe1XK55yfyIpXm2wDIjcisq8 0vic6J4eansWFawoIpScUQSDb6ZBNc2y81FgJLu+c7+oS/O3mEY83t1zxy6zGsBc4bmQ MoFg== X-Gm-Message-State: AOAM5334oLnkaaGZQBnasTnIgTG9+KLPajTeAgXc+ic7BJre7Es4Uha8 SI0Ff+Eag9QJWhC7pwQ/qXaAgE1k31k= X-Google-Smtp-Source: ABdhPJzizkViMSoox9HDvsDREEsWawD2RnyTG/8QNLVYai1GDaptVVvYvWXVZtR+7plNxQxwjOE7tQ== X-Received: by 2002:a19:8643:: with SMTP id i64mr20819575lfd.355.1618266888102; Mon, 12 Apr 2021 15:34:48 -0700 (PDT) Received: from grain.localdomain ([5.18.199.94]) by smtp.gmail.com with ESMTPSA id z17sm2252637lfr.131.2021.04.12.15.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 15:34:46 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 01A1E56013A; Tue, 13 Apr 2021 01:34:45 +0300 (MSK) Date: Tue, 13 Apr 2021 01:34:45 +0300 To: Vladislav Shpilevoy Message-ID: References: <20210408164151.1759348-1-gorcunov@gmail.com> <20210408164151.1759348-6-gorcunov@gmail.com> <0868de76-3941-ed34-3d7e-2f7328e30934@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.5 (2021-01-21) Subject: Re: [Tarantool-patches] [PATCH v21 5/6] box: implement box.lib module 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: tml Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Tue, Apr 13, 2021 at 12:08:49AM +0200, Vladislav Shpilevoy wrote: > > You don't need any of the 'm' object attributes in the hash if > the 'm' pointer is already included. It is unique. There can't be > 2 objects with the same pointer in the memory. Yeah. What about even simplier? On top of your patch since we don't need to call strlen. --- diff --git a/src/box/lua/lib.c b/src/box/lua/lib.c index f8ce1be80..fa44163e0 100644 --- a/src/box/lua/lib.c +++ b/src/box/lua/lib.c @@ -418,9 +418,8 @@ lbox_module_load_func(struct lua_State *L) * Make sure there is enough space for key, and formatting. */ char key[max_sym_len + 32]; - int bytes = snprintf(key, sizeof(key), "%p.%s", m, sym) + 1; - assert(bytes <= (int)sizeof(key)); - size_t len = strlen(key); + size_t len = (size_t)snprintf(key, sizeof(key), "%p.%s", m, sym); + assert(len > 1 && len < sizeof(key)); struct box_module_func *cf = cache_find(key, len); if (cf == NULL) {