From 3a13be1de38e79b6b7e0e7a6fa81f4c59c379f4e Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tarantool.org> Date: Wed, 21 Jun 2017 22:36:30 +0300 Subject: [PATCH] lua: fix lua_tofield() for 2**64 value exp2(64) <= UINT64_MAX is true due to type conversion. Use exp2(64) instead of UINT64_MAX (optimized out even on -O0). Fixes buggy box/indices_any_type.test.lua on x86_64 Closes #2472 --- src/lua/utils.c | 4 ++-- test/box/indices_any_type.result | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lua/utils.c b/src/lua/utils.c index b40abf54f5..b78b5d6e43 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -499,10 +499,10 @@ luaL_tofield(struct lua_State *L, struct luaL_serializer *cfg, int index, if (isfinite(num) && modf(num, &intpart) != 0.0) { field->type = MP_DOUBLE; field->dval = num; - } else if (num >= 0 && num <= UINT64_MAX) { + } else if (num >= 0 && num < exp2(64)) { field->type = MP_UINT; field->ival = (uint64_t) num; - } else if (num >= INT64_MIN && num <= INT64_MAX) { + } else if (num > -exp2(63) && num < exp2(63)) { field->type = MP_INT; field->ival = (int64_t) num; } else { diff --git a/test/box/indices_any_type.result b/test/box/indices_any_type.result index 051cb60518..dce9f754c1 100644 --- a/test/box/indices_any_type.result +++ b/test/box/indices_any_type.result @@ -393,12 +393,12 @@ s5:insert({0xFFFFFFFFFFFFFFFFULL}) ... s5:insert({ffi.new('double', ffi.C.exp2(64))}) -- success --- -- [0] +- [1.844674407371e+19] ... s5:select() --- - - [18446744073709551615] - - [0] + - [1.844674407371e+19] ... s5:truncate() --- -- GitLab