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 v2 1/4] sql: truncate values in type mismatch error
Date: Thu, 8 Jul 2021 00:09:12 +0200
Message-ID: <23623e4a-eb22-03b0-7e5b-841f30e725a4@tarantool.org> (raw)
In-Reply-To: <dadda45fb1a3e4b2dbc1c853f936826ce3b39b47.1625498636.git.imeevma@gmail.com>

Hi! Thanks for the patch!

See 2 comments below.

> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 6f3bf52e5..630f1a135 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -71,26 +72,35 @@ mem_is_field_compatible(const struct Mem *mem, enum field_type type)
>  const char *
>  mem_str(const struct Mem *mem)
>  {
> -	char buf[BUF_SIZE];
> +	char buf[STR_VALUE_MAX_LEN + 1];
>  	switch (mem->type) {
>  	case MEM_TYPE_NULL:
>  		return "NULL";
>  	case MEM_TYPE_STR:
> -		if ((mem->flags & MEM_Term) != 0)
> -			return mem->z;
> +		if (mem->n > STR_VALUE_MAX_LEN) {
> +			memcpy(buf, mem->z, STR_VALUE_MAX_LEN);
> +			buf[STR_VALUE_MAX_LEN] = '\0';
> +			return tt_sprintf("%s...", buf);

1. Can be done simpler using %.*s in tt_sprintf() with the length
limited by STR_VALUE_MAX_LEN.

> +		}
>  		return tt_cstr(mem->z, mem->n);
>  	case MEM_TYPE_INT:
>  		return tt_sprintf("%lld", mem->u.i);
>  	case MEM_TYPE_UINT:
>  		return tt_sprintf("%llu", mem->u.u);
>  	case MEM_TYPE_DOUBLE:
> -		sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r);
> +		sql_snprintf(STR_VALUE_MAX_LEN + 1, buf, "%!.15g", mem->u.r);
>  		return tt_sprintf("%s", buf);
>  	case MEM_TYPE_BIN:
>  		return "varbinary";
>  	case MEM_TYPE_MAP:
> -	case MEM_TYPE_ARRAY:
> -		return mp_str(mem->z);
> +	case MEM_TYPE_ARRAY: {
> +		const char *str = mp_str(mem->z);
> +		if (strlen(str) <= STR_VALUE_MAX_LEN)
> +			return str;
> +		memcpy(buf, str, STR_VALUE_MAX_LEN);
> +		buf[STR_VALUE_MAX_LEN] = '\0';
> +		return tt_sprintf("%s...", buf);

2. Ditto.

  reply	other threads:[~2021-07-07 22:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-05 15:27 [Tarantool-patches] [PATCH v2 0/4] sql: fix description of " Mergen Imeev via Tarantool-patches
2021-07-05 15:27 ` [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in " Mergen Imeev via Tarantool-patches
2021-07-07 22:09   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-07-12  8:50     ` Mergen Imeev via Tarantool-patches
2021-07-05 15:27 ` [Tarantool-patches] [PATCH v2 2/4] sql: properly show " Mergen Imeev via Tarantool-patches
2021-07-07 22:09   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-12  8:56     ` Mergen Imeev via Tarantool-patches
2021-07-05 15:27 ` [Tarantool-patches] [PATCH v2 3/4] sql: use proper type names in error descriptions Mergen Imeev via Tarantool-patches
2021-07-05 15:27 ` [Tarantool-patches] [PATCH v2 4/4] sql: make type mismatch error more informative Mergen Imeev via Tarantool-patches
2021-07-07 22:10   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-12  8:58     ` Mergen Imeev via Tarantool-patches
2021-07-12 21:38 ` [Tarantool-patches] [PATCH v2 0/4] sql: fix description of type mismatch error Vladislav Shpilevoy via Tarantool-patches
2021-07-13  7:03 [Tarantool-patches] [PATCH v2 0/4] sql: fix description of type mismatch errors Mergen Imeev via Tarantool-patches
2021-07-13  7:03 ` [Tarantool-patches] [PATCH v2 1/4] sql: truncate values in type mismatch error Mergen Imeev via Tarantool-patches
2021-07-13  8:51   ` Timur Safin 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=23623e4a-eb22-03b0-7e5b-841f30e725a4@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    /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

Tarantool development patches archive

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lists.tarantool.org/tarantool-patches/0 tarantool-patches/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tarantool-patches tarantool-patches/ https://lists.tarantool.org/tarantool-patches \
		tarantool-patches@dev.tarantool.org.
	public-inbox-index tarantool-patches

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git