From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org,
Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v1 1/1] lua: fix strange behaviour of tonumber64
Date: Mon, 16 Jul 2018 19:52:08 +0300 [thread overview]
Message-ID: <58f21346-5ae1-97fe-2231-0d86f3c9717f@tarantool.org> (raw)
In-Reply-To: <20180716140907.62lazzvz4vx2e7fz@tkn_work_nb>
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
next prev parent reply other threads:[~2018-07-16 16:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 11:21 [tarantool-patches] " Kirill Shcherbatov
2018-07-16 10:23 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-16 12:49 ` Alexander Turenko
2018-07-16 13:15 ` Vladislav Shpilevoy
2018-07-16 13:42 ` Alexander Turenko
2018-07-16 13:55 ` Vladislav Shpilevoy
2018-07-16 14:09 ` Alexander Turenko
2018-07-16 16:52 ` Kirill Shcherbatov [this message]
2018-07-17 9:35 ` Vladislav Shpilevoy
2018-07-17 11:27 ` Alexander Turenko
2018-07-17 12:03 ` Kirill Shcherbatov
2018-07-17 21:48 ` Vladislav Shpilevoy
2018-07-19 10:46 ` Kirill Yukhin
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=58f21346-5ae1-97fe-2231-0d86f3c9717f@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='[tarantool-patches] Re: [PATCH v1 1/1] lua: fix strange behaviour of tonumber64' \
/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