UB in various hypot() implementations (left-shifting a negative, number)

Dimitry Andric dim at FreeBSD.org
Sat Nov 16 20:40:57 UTC 2019


On 2019-11-16 18:02:29 UTC, Steve Kargl wrote:
 > The patch for hypotl() is likely unneeded as there is no shifting
 > of a negative integer in the code being changed.  Does csqrt_test.c
 > pass without Jeff's patch?

Yes, it passes.


 > This is the original code
 >
 >      u_int32_t high;
 >      t1 = 1.0;
 >      GET_HIGH_WORD(high,t1);
 >      SET_HIGH_WORD(t1,high+DESW(k));
 >
 > high + DESW(k) = high + k
 >                = 16383 + k
 >
 > and this is the code after the patch
 >
 >      t1 = 0.0;
 >      SET_HIGH_WORD(t1,ESW(k));
 >
 > ESW(k) = MAX_EXP - 1 + k
 >        = LDBL_MAX_EXP - 1 + k
 >        = 16384 - 1 + k
 >        = 16383 + k
 >
 > So, in principle there is no functional change.

What about t1 changing from 1.0 to 0?  If I revert just that line, all
tests do pass, including the csqrt test.

-Dimitry

PS: Apologies for any missing References: header in this mail, which 
might mess up threading in your mail client. I just subscribed to this list.


More information about the freebsd-numerics mailing list