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 7147825210 for ; Mon, 16 Jul 2018 06:23:39 -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 34dhvM0mjmdJ for ; Mon, 16 Jul 2018 06:23:39 -0400 (EDT) Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 29C98251E1 for ; Mon, 16 Jul 2018 06:23:39 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v1 1/1] lua: fix strange behaviour of tonumber64 References: From: Vladislav Shpilevoy Message-ID: <6b638fd3-58bc-2ed7-c32c-3f0a440d1f2b@tarantool.org> Date: Mon, 16 Jul 2018 13:23:36 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed 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: Kirill Shcherbatov , tarantool-patches@freelists.org Thanks for the patch! See 4 comments below. On 13/07/2018 14:21, Kirill Shcherbatov wrote: > Function tonumber64 has worked incorrectly with values less > than LLONG_MIN. > Now it works in the interval [LLONG_MIN, ULLONG_MAX] returning > nil otherwise. > > Closes #3466. > --- > Branch: https://github.com/tarantool/tarantool/compare/kshch/gh-3466-tonumber64-strange-behaviour > Issue: https://github.com/tarantool/tarantool/issues/3466 > > src/lua/init.c | 6 +++++- > test/box/misc.result | 19 +++++++++++++++++++ > test/box/misc.test.lua | 8 ++++++++ > 3 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/src/lua/init.c b/src/lua/init.c > index 9a96030..4b5285d 100644 > --- a/src/lua/init.c > +++ b/src/lua/init.c > @@ -222,7 +222,11 @@ lbox_tonumber64(struct lua_State *L) > if (argl == 0) { > lua_pushnil(L); > } else if (negative) { > - luaL_pushint64(L, -1 * (long long )result); > + if (result > -((unsigned long long )LLONG_MIN)) { 1. Please, do not enclose one-line bodies into {}. 2. How can you cast LLONG_MIN (that is negative) to the unsigned type? 3. Why not 'result > LLONG_MAX'? As I understand, abs(LLONG_MAX) == abs(LLONG_MIN), it is not? (http://www.cplusplus.com/reference/climits/) 4. Why the function is named to64, but we use non-explicitly sized types? I mean, why not to use uint64_t result, compare with INT64_MAX etc. According to the C standard, LLONG_MAX is not restricted with 64 bits. > + lua_pushnil(L); > + } else { > + luaL_pushint64(L, -result); > + } > } else { > luaL_pushuint64(L, result); > }