From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id D19796EC55; Tue, 27 Jul 2021 11:09:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D19796EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627373359; bh=2Bf7YyMyVqW/DuHpbdEzBWT7BAQ/zR4p4cXM2Jz0AmY=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KJtMKz2H6HyvFoxs2dQWC86KT7qRaodg/xWFb/16a/XUXIIAis6pnIFHrtCkCcjtd RtniK26vM0ZEBrh04gO59oztC9nlywD/+44njCZnl/UFArYR+BC1EUkb92NPjPZUN5 tg0IoM/zfDIcPY4/PWlLPnis5WY8I6gLvolQE8iw= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 73E886EC55 for ; Tue, 27 Jul 2021 11:09:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 73E886EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1m8I9N-0002el-Ne; Tue, 27 Jul 2021 11:09:18 +0300 Date: Tue, 27 Jul 2021 11:09:16 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210727080916.GA24960@tarantool.org> References: <1a255e29a58457eb9046cd1cd9940f2be1acc4e6.1626879974.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD941C43E597735A9C34755E0A9F196FCB739C645213AB7C8E0182A05F53808504011CDFCBF1FD9FC5BFD8932D404AF74E4125A690F80D453ACB2A2432D81D1FA8D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AC4684DF4EC4B256EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377A7A7D315BEE81B48638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8463AE4F4CD13180A9560E81DED4CF551117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A59D3B8D1F752D5067732549A6D3409B0D3C96E807CE9B0FE5D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7536C62C4FBC402878410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342B8615F5CFAD9D02D4BBF20B0821F0E6CA890A8A41982325805018C00E8FB30A8293F9634315B9DA1D7E09C32AA3244CE599B13CCA9FBE99E663CFFD505B3D87A995755A1445935E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMEANdStWW5/e42W6w2jwWQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D87C4A8478E742E54D84AE5C872F6905C83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix cast of small negative DOUBLE to INTEGER X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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.