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 3C2906F879; Wed, 26 Jan 2022 15:22:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3C2906F879 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1643199757; bh=8/SCHkxk6IMOPGg3ctkC1yKAl6LEeurlzPjzAxbIHL4=; 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=CgdQ5atHrhff4F+4IpDzh0OkM8gx36i5BUXME3XMmhc8rtb8e/7od+ukbYKgr4p3T ieCgrSeoiu1fNL/rlhpDg9v8AvXSX0XIs5y8jTt4LCTbRg1Ctt7SnqfLqnXXp146Fy fpjkWXkXDArkKWcs+P7jmcRexA+2sdO6W6s07tEE= 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 DEE026F87E for ; Wed, 26 Jan 2022 15:21:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DEE026F87E Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1nChIv-00089M-92; Wed, 26 Jan 2022 15:21:37 +0300 To: Sergey Ostanevich , Igor Munkin Date: Wed, 26 Jan 2022 15:19:34 +0300 Message-Id: <6ab9d085d486a481362259063598825a14f6876b.1643199076.git.skaplun@tarantool.org> 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: 4F1203BC0FB41BD9AA78FDF62ECAE61FE8F0416753E75F32ADD2080602F20CE6182A05F538085040FEFA775A70EA961379058F2C2B3FC10BE7EE1B2D3A08C9D19A208D50E571D23A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73F300A97FDD4E158EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637DB576DCB83B448D28638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CCD23CDD46A90D2774D7F70A7237BF33117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF2FB19FA2283D722F8E2839FE3EBEF12ACA8744E855F69FA9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE323A604FE95ED09DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343536C6A4332D8B8A1414C73614D5B5727984824A672FC780D5BDBA25675ADF3063936BF476C5D9C91D7E09C32AA3244CB2B8BE69537251A9C5EBF6C1D5D8224997FE24653F78E668927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojF0Kx79yI7sWftX73oxXzSQ== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4498AD98A1C65FEC2925B946E17A7E3F01922827624AD7D90F2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix tonumber("-0") in dual-number mode. 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 Sergey Kaplun. For DUALNUM build `tonumber("-0x0")` or `tonumber("-0")` returns 0 instead -0 due to the STRSCAN_OPT_TOINT option of `lj_strscan_scan()` and cast value to integer with losing information about its sign. This patch adds special checks for these corner cases during strscan. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#6548 --- src/lj_strscan.c | 8 ++++++-- test/tarantool-tests/lj-528-tonumber-0.test.lua | 10 ++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 4e4ef6d3..11d341ee 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c @@ -121,7 +121,8 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, /* Format-specific handling. */ switch (fmt) { case STRSCAN_INT: - if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { + if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && + !(x == 0 && neg)) { o->i = neg ? -(int32_t)x : (int32_t)x; return STRSCAN_INT; /* Fast path for 32 bit integers. */ } @@ -498,6 +499,9 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, if ((opt & STRSCAN_OPT_TONUM)) { o->n = neg ? -(double)x : (double)x; return STRSCAN_NUM; + } else if (x == 0 && neg) { + o->n = -0.0; + return STRSCAN_NUM; } else { o->i = neg ? -(int32_t)x : (int32_t)x; return STRSCAN_INT; @@ -515,7 +519,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); /* Try to convert number to integer, if requested. */ - if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { + if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT) && !tvismzero(o)) { double n = o->n; int32_t i = lj_num2int(n); if (n == (lua_Number)i) { o->i = i; 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 index 03ba2aff..f3ad53d3 100644 --- a/test/tarantool-tests/lj-528-tonumber-0.test.lua +++ b/test/tarantool-tests/lj-528-tonumber-0.test.lua @@ -1,15 +1,9 @@ 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. +-- See also https://github.com/LuaJIT/LuaJIT/issues/528, +-- https://github.com/LuaJIT/LuaJIT/pull/787. local test = tap.test('lj-528-tonumber-0') test:plan(1) -- 2.34.1