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 C7D7E6EC55; Wed, 28 Jul 2021 11:56:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C7D7E6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627462610; bh=vbFm7harwkJ7BluiGpne69uU5v6dksUjHkWLdX3moKc=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=T//VE7dmZYhi1HPqeCzOwnoW3wAKE+yJMPKO960CBCJt55C7zZdBXiQCH54S0Dus7 tlj0hGom6lp7curHJCXAt5kHXsgbL/mMDnitBDvFkomV8iXnBfoljJ4zECv6NZGJeI o+mbdqVD72aKYG19kG7EMdSkaKsh06C3rGMtt+SU= Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (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 15E206EC55 for ; Wed, 28 Jul 2021 11:56:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 15E206EC55 Received: by smtp33.i.mail.ru with esmtpa (envelope-from ) id 1m8fMv-0007XP-CX; Wed, 28 Jul 2021 11:56:49 +0300 To: Cc: References: <287af90465215d8f5dc37f1c147074387175bdf2.1627371599.git.imeevma@gmail.com> In-Reply-To: <287af90465215d8f5dc37f1c147074387175bdf2.1627371599.git.imeevma@gmail.com> Date: Wed, 28 Jul 2021 11:56:45 +0300 Message-ID: <008f01d7838e$7e75c100$7b614300$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQHJW2LWloR2IqNBCSQ6cNVgOdncyKt0ZhVQ Content-Language: ru X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C351B198F4576AC7B21928AAE70459C21B182A05F538085040D7D2C3AD6C9D254186603559A9E6C70F87AFA811D4C5A7B7EBB3905A729EC349 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BF6CFCE92D77DF21EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379E90269B204C5E5D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CA913F55E5331D88299F37045F5ACAE3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7B96B19DC4093321F206494F22AA87D6D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3251EFD5447B32ED6C0837EA9F3D19764C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637C970FD8DF19C51D2EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A58EF53F9C5978011CB67FB76BB673A68146F9011639263FF1D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75D299BBC8C521FD19410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A2EC120135420F90D3A5910CBB1EF331670734B55C49BB0EA79959CC8EBA957A3DB6621F330789CB1D7E09C32AA3244CEC5780AED59F9C0AE5F355D71EAD6D9A30452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiF1u9eOpfTSRqwidiXirjQ== X-Mailru-Sender: B5B6A6EBBD94DAD8C47A93838048902DC161EB39DAC33C9C79CA0B6169B3D905B932D4DCBEE97EA01EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: disallow cast of negative DOUBLE to UNSIGNED 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: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LGTM, thanks! : From: imeevma@tarantool.org : Subject: [PATCH v1 1/1] sql: disallow cast of negative DOUBLE to = UNSIGNED :=20 : Prior to this patch it was possible to use CAST( AS UNSIGNED) : and get negative result. For example, result of CAST(-1.5 AS UNSIGNED) : was -1. This patch removes this possibility. Now such cast can only : return UNSIGNED value. :=20 : Closes #6010 : --- : https://github.com/tarantool/tarantool/issues/6010 : = https://github.com/tarantool/tarantool/tree/imeevma/gh-6010-disallow-doub= le- : to-int-cast :=20 : ...-6010-disallow-negative-double-to-unsigned-cast | 4 ++++ : src/box/sql/mem.c | 2 +- : test/sql-tap/numcast.test.lua | 14 = +++++++++++++- : test/sql/types.result | 7 ++----- : 4 files changed, 20 insertions(+), 7 deletions(-) : create mode 100644 = changelogs/unreleased/gh-6010-disallow-negative-double- : to-unsigned-cast :=20 : diff --git = a/changelogs/unreleased/gh-6010-disallow-negative-double-to- : unsigned-cast = b/changelogs/unreleased/gh-6010-disallow-negative-double-to- : unsigned-cast : new file mode 100644 : index 000000000..566be594f : --- /dev/null : +++ = b/changelogs/unreleased/gh-6010-disallow-negative-double-to-unsigned- : cast : @@ -0,0 +1,4 @@ : +## bugfix/sql : + : +* Fixed explicit cast of negative DOUBLE to UNSIGNED, which could = return : +negative result (gh-6010). : diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c : index fa80f6d5a..e4ce233e0 100644 : --- a/src/box/sql/mem.c : +++ b/src/box/sql/mem.c : @@ -1061,7 +1061,7 @@ mem_cast_explicit(struct Mem *mem, enum = field_type : type) : case MEM_TYPE_BIN: : return bytes_to_uint(mem); : case MEM_TYPE_DOUBLE: : - return double_to_int(mem); : + return double_to_uint(mem); : case MEM_TYPE_BOOL: : return bool_to_int(mem); : default: : diff --git a/test/sql-tap/numcast.test.lua = b/test/sql-tap/numcast.test.lua : index b3aa64e76..20aea3c4b 100755 : --- a/test/sql-tap/numcast.test.lua : +++ b/test/sql-tap/numcast.test.lua : @@ -1,6 +1,6 @@ : #!/usr/bin/env tarantool : local test =3D require("sqltester") : -test:plan(31) : +test:plan(32) :=20 : --!./tcltestrunner.lua : -- 2013 March 20 : @@ -249,4 +249,16 @@ test:do_execsql_test( : 0 , 0.33333333333333, 0.33333333333333 : }) :=20 : +-- : +-- gh-6010: Make sure that a negative DOUBLE value cannot be = explicitly : cast to : +-- UNSIGNED. : +-- : +test:do_catchsql_test( : + "numcast-4", : + [[ : + SELECT CAST(-2.5 AS UNSIGNED); : + ]], { : + 1, "Type mismatch: can not convert double(-2.5) to unsigned" : +}) : + : test:finish_test() : diff --git a/test/sql/types.result b/test/sql/types.result : index a0b8668be..c1e1a8ef1 100644 : --- a/test/sql/types.result : +++ b/test/sql/types.result : @@ -1097,11 +1097,8 @@ box.execute("SELECT CAST(1.5 AS UNSIGNED);") : ... : box.execute("SELECT CAST(-1.5 AS UNSIGNED);") : --- : -- metadata: : - - name: COLUMN_1 : - type: unsigned : - rows: : - - [-1] : +- null : +- 'Type mismatch: can not convert double(-1.5) to unsigned' : ... : box.execute("SELECT CAST(true AS UNSIGNED);") : --- : -- : 2.25.1