[tarantool-patches] Re: [PATCH v1 1/1] lua: wrong 'tomap' work with nullable fields

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Aug 24 13:23:29 MSK 2018


Hi! Thanks for the fixes!

> commit 066db38393316c486b9edef0d71e854c3e4fdc78
> Author: Mergen Imeev <imeevma at gmail.com>
> Date:   Wed Aug 22 13:33:22 2018 +0300
> 
>      lua: wrong 'tomap' work with nullable fields
> 
>      Tuple method 'tomap' in some cases worked improperly if tuple
>      length less than it should be according to space format. Fixed
>      in this patch.
> 
>      Closes #3631
> 
> diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
> index 7ca4299..cd96152 100644
> --- a/src/box/lua/tuple.c
> +++ b/src/box/lua/tuple.c
> @@ -284,12 +284,11 @@ lbox_tuple_to_map(struct lua_State *L)
>           luaL_error(L, "Usage: tuple:tomap()");
>       const struct tuple *tuple = lua_checktuple(L, 1);
>       const struct tuple_format *format = tuple_format(tuple);
> -    const struct tuple_field *field = &format->fields[0];
>       const char *pos = tuple_data(tuple);
>       int field_count = (int)mp_decode_array(&pos);
>       int n_named = format->dict->name_count;
>       lua_createtable(L, field_count, n_named);
> -    for (int i = 0; i < n_named; ++i, ++field) {
> +    for (int i = 0; i < MIN(field_count, n_named); ++i) {

It is not ok to calculate MIN on each iteration.
Either N_named and field_count can not change during
iteration. I fixed it in a separate commit on the
branch. Please, look and squash. And send the patch
as v2 to Vova D.

>           /* Access by name. */
>           const char *name = format->dict->names[i];
>           lua_pushstring(L, name);

My diff (so far it is required by SOP since recently):

diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index cd961526c..5acbecb23 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -288,7 +288,8 @@ lbox_tuple_to_map(struct lua_State *L)
  	int field_count = (int)mp_decode_array(&pos);
  	int n_named = format->dict->name_count;
  	lua_createtable(L, field_count, n_named);
-	for (int i = 0; i < MIN(field_count, n_named); ++i) {
+	int named_and_presented = MIN(field_count, n_named);
+	for (int i = 0; i < named_and_presented; ++i) {
  		/* Access by name. */
  		const char *name = format->dict->names[i];
  		lua_pushstring(L, name);




More information about the Tarantool-patches mailing list