On Tue, Apr 30, 2024 at 06:18:23PM +0100, colin.i.k...@gmail.com wrote: > >Synopsis: sincosl() segmentation fault > >Category: library > >Environment: > System : OpenBSD 7.5 > Details : OpenBSD 7.5 (GENERIC.MP) #82: Wed Mar 20 15:48:40 MDT 2024 > > dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP > > Architecture: OpenBSD.amd64 > Machine : amd64 > >Description: > calls to sincosl with long double arguments causes a segmentation fault. > >How-To-Repeat: > > openbsd75$ cat x.c > #include <math.h> > > int main(void) > { > long double theta = 0.0, s, c; > > sincosl(theta, &s, &c); > } > openbsd75$ clang x.c -lm -o x > openbsd75$ ./x > Segmentation fault (core dumped)
NAN also crashes. Both give the expected result with this diff. Thanks for the report. Index: lib/libm/src/s_sincosl.c =================================================================== RCS file: /cvs/src/lib/libm/src/s_sincosl.c,v diff -u -p -U10 -r1.1 s_sincosl.c --- lib/libm/src/s_sincosl.c 10 Mar 2018 20:52:58 -0000 1.1 +++ lib/libm/src/s_sincosl.c 1 May 2024 03:47:16 -0000 @@ -65,26 +65,28 @@ sincosl(long double x, long double *sn, if (z.e < M_PI_4) { /* * If x = +-0 or x is a subnormal number, then sin(x) = x and * cos(x) = 1. */ if (z.bits.ext_exp == 0) { *sn = x; *cs = 1; } else __kernel_sincosl(x, 0, 0, sn, cs); + return; } /* If x = NaN or Inf, then sin(x) and cos(x) are NaN. */ if (z.bits.ext_exp == 32767) { *sn = x - x; *cs = x - x; + return; } /* Split z.e into a 24-bit representation. */ e0 = ilogbl(z.e) - 23; z.e = scalbnl(z.e, -e0); for (i = 0; i < NX; i++) { xd[i] = (double)((int32_t)z.e); z.e = (z.e - xd[i]) * two24; }