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 7E1FB6F879; Wed, 26 Jan 2022 15:22:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7E1FB6F879 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1643199726; bh=esHpOKhGgykAreZIGMsPKFTbegbJ/KyY8QteOQxp3xk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rUKKenwTUmN8pJf2sgsOyjCsvXxj9iVy3Ls2TpGZ91C9HG3WLoMRTrOCx+O2yctsu I1ziLU2EdNSxNWxB/tSVXJGinTazHTZJu9CRupcVox4mXtxmwraGnOttRPLSdQQ2RL dlGs42EYGrJk5gJD8lQjpxBKXLM6fiDwg4QdviFQ= 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 dev.tarantool.org (Postfix) with ESMTPS id 370AA6F879 for ; Wed, 26 Jan 2022 15:21:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 370AA6F879 Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1nChIt-00089M-Gl; Wed, 26 Jan 2022 15:21:35 +0300 To: Sergey Ostanevich , Igor Munkin Date: Wed, 26 Jan 2022 15:19:33 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AA78FDF62ECAE61F7A922168D8AD45D749A6A71140E6560E182A05F5380850407E817C8A85A9DB80B20E8D6500A42771F52D5ED1177DE4CF9D28EEBC78164498 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E3137013C338FE3BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748424D8FCCA3295D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8DB71DC38D5C7A2AA214F2BD90B06E920117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3733B5EC72352B9FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF2FB19FA2283D722952F5EA94342CDFABC782F51C3EF025E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE323A604FE95ED09DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348F9E8EBB462314872C6EDA7C90163A852014B60C8FC97DFA45A034D03B7F11B519923C399721FD8B1D7E09C32AA3244CD6CD7D64BAE67B38FE47EFD9BF17473F250262A5EE9971B0927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojF0Kx79yI7sVo0w7dYr+WRg== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB40A0638825BB86379925B946E17A7E3F06A23C528FA807811F2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/2] Fix tonumber("-0"). 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by bluecheetah001. (cherry picked from 45a7e5073ce0a59465fef0b80bb08bd4e76b7979) Common case for scanning a string containing a number is a string with a decimal number. For this case, a decimal number first casts to int32_t and later to double (lua_Number) if necessary. Information about sign of 0 is lost during the cast to int32_t. So resulting TValue contains `0.` instead of `-0.`. This patch removes cast to int32_t for the case when resulting TValue contains double value. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#6548 --- src/lj_strscan.c | 5 ++--- .../lj-528-tonumber-0.test.lua | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/tarantool-tests/lj-528-tonumber-0.test.lua diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 08f41f19..4e4ef6d3 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c @@ -495,12 +495,11 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, /* Fast path for decimal 32 bit integers. */ if (fmt == STRSCAN_INT && base == 10 && (dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) { - int32_t y = neg ? -(int32_t)x : (int32_t)x; if ((opt & STRSCAN_OPT_TONUM)) { - o->n = (double)y; + o->n = neg ? -(double)x : (double)x; return STRSCAN_NUM; } else { - o->i = y; + o->i = neg ? -(int32_t)x : (int32_t)x; return STRSCAN_INT; } } diff --git a/test/tarantool-tests/lj-528-tonumber-0.test.lua b/test/tarantool-tests/lj-528-tonumber-0.test.lua new file mode 100644 index 00000000..03ba2aff --- /dev/null +++ b/test/tarantool-tests/lj-528-tonumber-0.test.lua @@ -0,0 +1,19 @@ +local tap = require('tap') + +-- Test disabled for DUALNUM mode default for some arches. +-- See also https://github.com/LuaJIT/LuaJIT/pull/787. +require("utils").skipcond( + jit.arch ~= "x86" and jit.arch ~= "x64", + jit.arch.." in DUALNUM mode is clumsy for now" +) + +-- Test file to demonstrate LuaJIT `tonumber('-0')` incorrect +-- behaviour. +-- See also https://github.com/LuaJIT/LuaJIT/issues/528. +local test = tap.test('lj-528-tonumber-0') +test:plan(1) + +-- As numbers `-0 == 0`, so convert it back to string. +test:ok(tostring(tonumber('-0')) == '-0', 'correct "-0" string parsing') + +os.exit(test:check() and 0 or 1) -- 2.34.1