Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Dec 2018 22:32:06 -0500
From:      Pedro Giffuni <pfg@FreeBSD.org>
To:        freebsd-numerics@freebsd.org
Cc:        sgk@troutmask.apl.washington.edu
Subject:   Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM)
Message-ID:  <06c8b6a2-ed26-f255-3947-c79b593a9dea@FreeBSD.org>
In-Reply-To: <20181231152230.GC823@troutmask.apl.washington.edu>
References:  <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> <20181231151904.GB823@troutmask.apl.washington.edu> <20181231152230.GC823@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------77F699FB60D2895086164B43
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Hmm ...

Looking at the changes in musl's libc I found this issue which seems 
real (although somewhat theoretical):

https://git.musl-libc.org/cgit/musl/commit/src/math?id=688d3da0f1730daddbc954bbc2d27cc96ceee04c

Is the attached patch acceptable?


Also, their code is bit different here:

https://git.musl-libc.org/cgit/musl/commit/src/math?id=282b1cd26649d69de038111f5876853df6ddc345

but we may also have to check fmaf(-0x1.26524ep-54, -0x1.cb7868p+11, 
0x1.d10f5ep-29).

Cheers,

Pedro.


--------------77F699FB60D2895086164B43
Content-Type: text/x-patch;
 name="msun-pow-ub.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="msun-pow-ub.diff"

Index: lib/msun/src/e_pow.c
===================================================================
--- lib/msun/src/e_pow.c	(revision 342665)
+++ lib/msun/src/e_pow.c	(working copy)
@@ -130,6 +130,7 @@
 	if(hx<0) {
 	    if(iy>=0x43400000) yisint = 2; /* even integer y */
 	    else if(iy>=0x3ff00000) {
+		uint32_t j;	/* Avoid UB in bit operations below. */
 		k = (iy>>20)-0x3ff;	   /* exponent */
 		if(k>20) {
 		    j = ly>>(52-k);

--------------77F699FB60D2895086164B43--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?06c8b6a2-ed26-f255-3947-c79b593a9dea>