Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] Re: [PATCH v1 4/4] box: refactor tuple_init_field_map to use bitmap
Date: Sat, 29 Dec 2018 19:25:46 +0300	[thread overview]
Message-ID: <20181229162546.npbzbaasxe6ufk3p@esperanza> (raw)
In-Reply-To: <a29b2265-a793-e12f-cee5-f3d2fdb5f978@tarantool.org>

On Sat, Dec 29, 2018 at 03:58:34PM +0300, Kirill Shcherbatov wrote:
> Refactored tuple_init_field_map to fill a local bitmap and

It's not refactoring, it's a rework.

> compare it with template required_fields bitmap containing
> information about required fields. Each field is mapped to
> bitmap with field:id - unique field identifier.
> This approach to check the required fields will work even after
> the introduction of JSON paths, when the field tree becomes
> multilevel.
> 
> Needed for #1012

> @@ -440,15 +484,30 @@ tuple_init_field_map(struct tuple_format *format, uint32_t *field_map,
>  			 (unsigned) format->exact_field_count);
>  		return -1;
>  	}
> -	if (validate && field_count < format->min_field_count) {
> -		diag_set(ClientError, ER_MIN_FIELD_COUNT,
> -			 (unsigned) field_count,
> -			 (unsigned) format->min_field_count);
> -		return -1;
> -	}
>  
>  	/* first field is simply accessible, so we do not store offset to it */
>  	struct tuple_field *field = tuple_format_field(format, 0);
> +	/*
> +	 * Allocate fields_bitmap - a copy of the initialized
> +	 * format:required_fields bitmap. The field:id bits would
> +	 * be nullified for founded fields during tuple parse to
> +	 * raise an error when some required field is missing.
> +	 */
> +	struct region *region = &fiber()->gc;
> +	char *fields_bitmap = NULL;
> +	uint32_t fields_bitmap_sz = bitmap_size(format->total_field_count);
> +	if (validate) {
> +		fields_bitmap = region_alloc(region, fields_bitmap_sz);
> +		if (fields_bitmap == NULL) {
> +			diag_set(OutOfMemory, fields_bitmap_sz, "calloc",

s/calloc/region

Memory allocated on the region isn't freed when the function returns...

> +				"required_fields");
> +			return -1;
> +		}
> +		memcpy(fields_bitmap, format->required_fields,
> +		       fields_bitmap_sz);
> +		if (field_count > 0)
> +			bit_clear(fields_bitmap, field->id);
> +	}
>  	if (validate &&
>  	    !field_mp_type_is_compatible(field->type, mp_typeof(*pos),
>  					 tuple_field_is_nullable(field))) {

If field_count is 0, then you'll access uninitialized memory here ^^^

I'm kinda tired of reviewing this simple patch so I fixed these issues
by myself, fixed grammar in the comments, and pushed the patch to 2.1.

  parent reply	other threads:[~2018-12-29 16:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27 11:15 [PATCH v1 0/4] box: JSON preparatory patchset Kirill Shcherbatov
2018-12-27 11:15 ` [PATCH v1 1/4] lib: introduce json_tree_snprint_path Kirill Shcherbatov
2018-12-27 18:51   ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 2/4] lib: introduce json_token_is_leaf helper Kirill Shcherbatov
2018-12-27 18:52   ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 3/4] box: introduce bitmap_majority_test routine Kirill Shcherbatov
2018-12-27 18:59   ` Vladimir Davydov
2018-12-29 12:58     ` [tarantool-patches] " Kirill Shcherbatov
2018-12-29 13:19       ` Vladimir Davydov
2018-12-29 13:57         ` Kirill Shcherbatov
2018-12-29 16:16           ` Vladimir Davydov
2018-12-27 11:15 ` [PATCH v1 4/4] box: refactor tuple_init_field_map to use bitmap Kirill Shcherbatov
2018-12-27 11:48   ` [tarantool-patches] " Konstantin Osipov
2018-12-27 19:12   ` Vladimir Davydov
2018-12-29 12:58     ` [tarantool-patches] " Kirill Shcherbatov
2018-12-29 13:22       ` Vladimir Davydov
2018-12-29 16:25       ` Vladimir Davydov [this message]
2018-12-27 19:13 ` [PATCH v1 0/4] box: JSON preparatory patchset Vladimir Davydov

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=20181229162546.npbzbaasxe6ufk3p@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] Re: [PATCH v1 4/4] box: refactor tuple_init_field_map to use bitmap' \
    /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