From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 647D020E6E for ; Mon, 16 Jul 2018 12:52:11 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lBGy5M4lfVFO for ; Mon, 16 Jul 2018 12:52:11 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 1D84920E3F for ; Mon, 16 Jul 2018 12:52:11 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v1 1/1] lua: fix strange behaviour of tonumber64 References: <6b638fd3-58bc-2ed7-c32c-3f0a440d1f2b@tarantool.org> <20180716124949.3uhj5zrkivphdnaw@tkn_work_nb> <20180716134210.zp3tckp3gcgchm4q@tkn_work_nb> <56a17552-ddcf-08cd-3ce1-78018f9dc748@tarantool.org> <20180716140907.62lazzvz4vx2e7fz@tkn_work_nb> From: Kirill Shcherbatov Message-ID: <58f21346-5ae1-97fe-2231-0d86f3c9717f@tarantool.org> Date: Mon, 16 Jul 2018 19:52:08 +0300 MIME-Version: 1.0 In-Reply-To: <20180716140907.62lazzvz4vx2e7fz@tkn_work_nb> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, Vladislav Shpilevoy Thank you for review. =========================================== diff --git a/src/lua/init.c b/src/lua/init.c index 9a96030..65addc1 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -222,7 +222,10 @@ lbox_tonumber64(struct lua_State *L) if (argl == 0) { lua_pushnil(L); } else if (negative) { - luaL_pushint64(L, -1 * (long long )result); + if (result != 0 && result - 1 > INT64_MAX) + lua_pushnil(L); + else + luaL_pushint64(L, -result); } else { luaL_pushuint64(L, result); } diff --git a/test/box/misc.result b/test/box/misc.result index f332a8c..fa9926b 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -640,6 +640,25 @@ tostring(tonumber64('1234567890123456')) == '1234567890123456ULL' --- - true ... +-- +-- gh-3466: Strange behaviour of tonumber64 function +-- +tostring(tonumber64('18446744073709551615')) == '18446744073709551615ULL' +--- +- true +... +tonumber64('18446744073709551616') == nil +--- +- true +... +tostring(tonumber64('-9223372036854775808')) == '-9223372036854775808LL' +--- +- true +... +tonumber64('-9223372036854775809') == nil +--- +- true +... tonumber64('0x12') == 18 --- - true diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua index e24228a..0b4ea21 100644 --- a/test/box/misc.test.lua +++ b/test/box/misc.test.lua @@ -165,6 +165,14 @@ tostring(tonumber64('12345678901234')) == '12345678901234' tostring(tonumber64('123456789012345')) == '123456789012345ULL' tostring(tonumber64('1234567890123456')) == '1234567890123456ULL' +-- +-- gh-3466: Strange behaviour of tonumber64 function +-- +tostring(tonumber64('18446744073709551615')) == '18446744073709551615ULL' +tonumber64('18446744073709551616') == nil +tostring(tonumber64('-9223372036854775808')) == '-9223372036854775808LL' +tonumber64('-9223372036854775809') == nil + tonumber64('0x12') == 18 tonumber64('0x12', 16) == 18 tonumber64('0x12', 17) == nil