[Tarantool-patches] [PATCH v4 01/16] sql: remove MEM_Zero flag from struct MEM

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Oct 5 00:51:42 MSK 2021


Hi! Thanks for the patch!

See 2 comments below.

> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 29d713fd0..ff0c461ce 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -1272,11 +1272,19 @@ zeroblobFunc(sql_context * context, int argc, sql_value ** argv)
>  	n = mem_get_int_unsafe(argv[0]);
>  	if (n < 0)
>  		n = 0;
> -	if (sql_result_zeroblob64(context, n) != 0) {
> +	if (n > sql_get()->aLimit[SQL_LIMIT_LENGTH]) {
>  		diag_set(ClientError, ER_SQL_EXECUTE, "string or binary string"\
>  			 "is too big");
>  		context->is_aborted = true;
> +		return;
> +	}
> +	char *str = sqlDbMallocRawNN(sql_get(), n);
> +	memset(str, 0, n);

1. There is sqlDbMallocZero().

> +	if (str == NULL) {
> +		context->is_aborted = true;
> +		return;
>  	}
> +	mem_set_bin_allocated(context->pOut, str, n);
>  }
>  
>  /*
> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 5e23c901c..24d6d7dbf 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -1869,8 +1850,6 @@ mem_get_bin(const struct Mem *mem, const char **s)
>  		*s = mem->n > 0 ? mem->z : NULL;
>  		return 0;
>  	}
> -	if (mem->type != MEM_TYPE_BIN || (mem->flags & MEM_Zero) != 0)
> -		return -1;

2. If the type is not MEM_TYPE_BIN, you will return garbage. Maybe
keep return -1 for other types?

>  	*s = mem->z;
>  	return 0;
>  }


More information about the Tarantool-patches mailing list