From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14800 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] math: fix signed int left shift ub in sqrt Date: Sun, 13 Oct 2019 17:03:19 +0200 Message-ID: <20191013150319.GJ7832@port70.net> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="jho1yZJdad60DJr+" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="247069"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-14816-gllmg-musl=m.gmane.org@lists.openwall.com Sun Oct 13 17:03:41 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1iJfPJ-0012An-2O for gllmg-musl@m.gmane.org; Sun, 13 Oct 2019 17:03:41 +0200 Original-Received: (qmail 22295 invoked by uid 550); 13 Oct 2019 15:03:37 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 22256 invoked from network); 13 Oct 2019 15:03:31 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:14800 Archived-At: --jho1yZJdad60DJr+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline old fdlibm bug, only affects soft float targets. --jho1yZJdad60DJr+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-math-fix-signed-int-left-shift-ub-in-sqrt.patch" >From b877237b506e03fd3c92ad7b39adbac5e1b74441 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 13 Oct 2019 14:54:31 +0000 Subject: [PATCH] math: fix signed int left shift ub in sqrt Both sqrt and sqrtf shifted the signed exponent as signed int to adjust the bit representation of the result. There are signed right shifts too in the code but those are implementation defined and are expected to compile to arithmetic shift on supported compilers and targets. --- src/math/sqrt.c | 3 +-- src/math/sqrtf.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/math/sqrt.c b/src/math/sqrt.c index b2775673..f1f6d76c 100644 --- a/src/math/sqrt.c +++ b/src/math/sqrt.c @@ -179,7 +179,6 @@ double sqrt(double x) ix1 = q1>>1; if (q&1) ix1 |= sign; - ix0 += m << 20; - INSERT_WORDS(z, ix0, ix1); + INSERT_WORDS(z, ix0 + ((uint32_t)m << 20), ix1); return z; } diff --git a/src/math/sqrtf.c b/src/math/sqrtf.c index 28cb4ad3..d6ace38a 100644 --- a/src/math/sqrtf.c +++ b/src/math/sqrtf.c @@ -78,7 +78,6 @@ float sqrtf(float x) } } ix = (q>>1) + 0x3f000000; - ix += m << 23; - SET_FLOAT_WORD(z, ix); + SET_FLOAT_WORD(z, ix + ((uint32_t)m << 23)); return z; } -- 2.23.0 --jho1yZJdad60DJr+--