mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: [PATCH] math: fix pow signed shift ub
Date: Tue, 4 Oct 2016 03:58:56 +0200	[thread overview]
Message-ID: <20161004015856.GL1280@port70.net> (raw)

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


                 reply	other threads:[~2016-10-04  1:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161004015856.GL1280@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).