Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix cast of small negative DOUBLE to INTEGER
Date: Tue, 27 Jul 2021 11:09:16 +0300	[thread overview]
Message-ID: <20210727080916.GA24960@tarantool.org> (raw)
In-Reply-To: <ab80fa5b-7e1d-d93a-4a8a-3512848d80a0@tarantool.org>

Hi! Thank you for the review! My answers below.

On Mon, Jul 26, 2021 at 09:47:21PM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> > diff --git a/changelogs/unreleased/gh-6225-cast-of-small-negative-double-to-int.md b/changelogs/unreleased/gh-6225-cast-of-small-negative-double-to-int.md
> > new file mode 100644
> > index 000000000..9f5d62231
> > --- /dev/null
> > +++ b/changelogs/unreleased/gh-6225-cast-of-small-negative-double-to-int.md
> > @@ -0,0 +1,4 @@
> > +## bugfix/sql
> > +
> > +* Fixed assert on cast of DOUBLE value that greater than -1.0 and less than 0.0
> > +  to INTEGER and UNSIGNED (gh-6255).
> 
> 1. I tried to revert the patch and only got an error, not an assertion.
This is because I rebased this patch above "sql: disallow cast of negative
DOUBLE to UNSIGNED". You can get an assert if you cast to INTEGER instead.

> 
> > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> > index e4ce233e0..6b95e41d3 100644
> > --- a/src/box/sql/mem.c
> > +++ b/src/box/sql/mem.c
> > @@ -1322,7 +1322,7 @@ mem_get_uint(const struct Mem *mem, uint64_t *u)
> >  	}
> >  	if (mem->type == MEM_TYPE_DOUBLE) {
> >  		double d = mem->u.r;
> > -		if (d >= 0 && d < (double)UINT64_MAX) {
> > +		if (d > -1.0 && d < (double)UINT64_MAX) {
> 
> 2. I see there are 6 changes extending 0 to -1.0, but only 2
> tests. Can you cover all the changed places?
I tried bo find a test, but this is quite problematic:
For double_to_int_precise()/double_to_uint_precise() it actually does not matter
since "(double)(uint64_t)d == d" check return false for any number greater
than -1 and less than 0. I decided to change these functions so the first
codition in IF would be unlinked to the third.

For mem_get_int() it actually matters since it changes values of is_neg.
However, this flag is ignored everywhere, so no test can be provided.

Function mem_get_uint() is actually the only one, which wrongly returns -1 in
case it gets double value that less than 0 and more than -1. However, the only
case when this matters is actually inside of mem_get_uint_unsafe(), which
returns 0 in case mem_get_uint() returns -1. Unexpectedly, this is the value
that should be returned if mem_get_uint() gets a double value less than 0 and
greater than -1. So this error is covered too.

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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 15:07 Mergen Imeev via Tarantool-patches
2021-07-26 19:47 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-27  8:09   ` Mergen Imeev via Tarantool-patches [this message]
2021-07-28 21:55     ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29  6:45 Mergen Imeev via Tarantool-patches
2021-08-02 17:04 Mergen Imeev via Tarantool-patches
2021-08-04  8:24 Mergen Imeev via Tarantool-patches
2021-08-04 14:02 ` Kirill Yukhin via Tarantool-patches
2021-08-04 15:07   ` Vitaliia Ioffe via Tarantool-patches
2021-08-05  9:36 ` Kirill Yukhin 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=20210727080916.GA24960@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 cast of small negative DOUBLE to INTEGER' \
    /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