[Tarantool-patches] [PATCH v21 5/6] box: implement box.lib module

Cyrill Gorcunov gorcunov at gmail.com
Tue Apr 13 01:34:45 MSK 2021


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) {



More information about the Tarantool-patches mailing list