Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: imeevma@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix a segfault in hex() on receiving zeroblob
Date: Thu, 26 Aug 2021 22:42:00 +0200	[thread overview]
Message-ID: <9f174b3c-31c6-2276-028d-22c6332f42db@tarantool.org> (raw)
In-Reply-To: <ce439dcb79a57e9f825f09f3cb6c8859d86d7f5d.1629976249.git.imeevma@gmail.com>

Thanks for the patch!

See 2 comments below.

> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index c063552d6..2ff368dc7 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -53,6 +53,49 @@
> +/** Implementation of the HEX() SQL built-in function. */
> +static void
> +func_hex(struct sql_context *ctx, int argc, struct Mem **argv)
> +{
> +	assert(argc == 1);
> +	(void)argc;
> +	if (argv[0]->type == MEM_TYPE_NULL)
> +		return mem_set_null(ctx->pOut);
> +
> +	assert(argv[0]->type == MEM_TYPE_BIN && argv[0]->n >= 0);
> +	assert((argv[0]->flags & MEM_Zero) == 0 || argv[0]->u.nZero >= 0);
> +	uint32_t size = 2 * argv[0]->n;
> +	if ((argv[0]->flags & MEM_Zero) != 0)
> +		size += 2 * argv[0]->u.nZero;
> +	if (size == 0)
> +		return mem_set_str0_static(ctx->pOut, "");
> +
> +	char *str = sqlDbMallocRawNN(sql_get(), size);
> +	if (str == NULL) {
> +		ctx->is_aborted = true;
> +		return;
> +	}
> +	for (int i = 0; i < argv[0]->n; ++i) {
> +		char c = argv[0]->z[i];
> +		str[2 * i] = hexdigits[(c >> 4) & 0xf];
> +		str[2 * i + 1] = hexdigits[c & 0xf];
> +	}
> +	if ((argv[0]->flags & MEM_Zero) != 0) {
> +		for (int i = 0; i < argv[0]->u.nZero; ++i) {
> +			int j = argv[0]->n + i;
> +			str[2 * j] = '0';
> +			str[2 * j + 1] = '0';

1. The same as for the patch for 2.8 branch.

> +		}
> +	}
> +	mem_set_str_allocated(ctx->pOut, str, size);
> +}
> @@ -2034,7 +2042,7 @@ static struct sql_func_definition definitions[] = {
>  	{"GROUP_CONCAT", 2, {FIELD_TYPE_VARBINARY, FIELD_TYPE_VARBINARY},
>  	 FIELD_TYPE_VARBINARY, groupConcatStep, groupConcatFinalize},
>  
> -	{"HEX", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_STRING, hexFunc, NULL},
> +	{"HEX", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_STRING, func_hex, NULL},

2. What is the final name pattern? I see among new function names

- trim_func - 'func' suffix

- sql_func_uuid, sql_func_version - 'sql_func' prefix

- sql_builtin_stub - 'sql' prefix

- sum_step - no prefixes or suffixes

now you add a fifth way:

- func_hex - 'func' prefix.

I suggest to choose one way to use for all new function names.

  reply	other threads:[~2021-08-26 20:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 11:11 Mergen Imeev via Tarantool-patches
2021-08-26 20:42 ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-08-27  8:26   ` Mergen Imeev via Tarantool-patches
2021-08-27 21:31     ` Vladislav Shpilevoy via Tarantool-patches
  -- strict thread matches above, loose matches on Subject: below --
2021-10-05 12:49 Mergen Imeev via Tarantool-patches
2021-08-30  6:30 Mergen Imeev via Tarantool-patches
2021-08-31 19:32 ` Timur Safin via Tarantool-patches
2021-09-01  8:44   ` Mergen Imeev via Tarantool-patches
2021-09-03 19:19     ` Safin Timur via Tarantool-patches
2021-09-06  9:45       ` Mergen Imeev via Tarantool-patches
2021-09-06 20:32         ` Safin Timur via Tarantool-patches
2021-09-07  9:16           ` Mergen Imeev via Tarantool-patches
2021-08-30  6:20 Mergen Imeev via Tarantool-patches
2021-09-03 19:20 ` Safin Timur via Tarantool-patches
2021-08-26 11:10 Mergen Imeev via Tarantool-patches
2021-08-26 20:31 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-27  7:54   ` Mergen Imeev via Tarantool-patches
2021-08-27 21:52     ` Vladislav Shpilevoy via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9f174b3c-31c6-2276-028d-22c6332f42db@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix a segfault in hex() on receiving zeroblob' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox