From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10553 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] math: fix pow signed shift ub Date: Tue, 4 Oct 2016 03:58:56 +0200 Message-ID: <20161004015856.GL1280@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1475546364 1728 195.159.176.226 (4 Oct 2016 01:59:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Oct 2016 01:59:24 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-10566-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 04 03:59:20 2016 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.84_2) (envelope-from ) id 1brF0h-0007I2-6Z for gllmg-musl@m.gmane.org; Tue, 04 Oct 2016 03:59:11 +0200 Original-Received: (qmail 20378 invoked by uid 550); 4 Oct 2016 01:59:09 -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 20349 invoked from network); 4 Oct 2016 01:59:08 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:10553 Archived-At: j is int32_t and thus j<<31 is undefined if j==1, so j is changed to uint32_t locally as a quick fix, the generated code is not affected. (this is a strict conformance fix, future c standard may allow 1<<31, see DR 463. the bug was inherited from freebsd fdlibm, the proper fix is to use uint32_t for all bit hacks, but that requires more intrusive changes.) reported by Daniel Sabogal --- src/math/pow.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math/pow.c b/src/math/pow.c index b66f632..3ddc1b6 100644 --- a/src/math/pow.c +++ b/src/math/pow.c @@ -125,11 +125,11 @@ double pow(double x, double y) else if (iy >= 0x3ff00000) { k = (iy>>20) - 0x3ff; /* exponent */ if (k > 20) { - j = ly>>(52-k); + uint32_t j = ly>>(52-k); if ((j<<(52-k)) == ly) yisint = 2 - (j&1); } else if (ly == 0) { - j = iy>>(20-k); + uint32_t j = iy>>(20-k); if ((j<<(20-k)) == iy) yisint = 2 - (j&1); } -- 2.10.0