[PATCH 5/8] math: Fix UB on cbrtf
Carlos O'Donell
carlos@redhat.com
Tue Apr 29 12:48:04 GMT 2025
On 4/25/25 4:54 PM, Adhemerval Zanella wrote:
> The left shift overflows for 'int64_t', use unsigned instead. It syncs
> with CORE-MATH commit f7c7408d1749ec2859ea249495af699359ae559b.
>
> Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
LGTM.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> sysdeps/ieee754/flt-32/s_cbrtf.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/ieee754/flt-32/s_cbrtf.c b/sysdeps/ieee754/flt-32/s_cbrtf.c
> index 5a7a9a952d..df9e888c1f 100644
> --- a/sysdeps/ieee754/flt-32/s_cbrtf.c
> +++ b/sysdeps/ieee754/flt-32/s_cbrtf.c
> @@ -3,7 +3,7 @@
> Copyright (c) 2023, 2024 Alexei Sibidanov.
>
> The original version of this file was copied from the CORE-MATH
> -project (file src/binary32/cbrt/cbrtf.c, revision bc385c2).
> +project (file src/binary32/cbrt/cbrtf.c, revision f7c7408d).
OK.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> @@ -61,8 +61,8 @@ __cbrtf (float x)
> e += 899;
> uint32_t et = e / 3, it = e % 3;
> uint64_t isc = escale[it].u;
> - isc += (int64_t) (et - 342) << 52;
> - isc |= (int64_t) sgn << 63;
> + isc += (uint64_t) (et - 342) << 52;
> + isc |= (uint64_t) sgn << 63;
> double cvt2 = asdouble (isc);
> static const double c[] =
> {
OK.
commit f7c7408d1749ec2859ea249495af699359ae559b
Author: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Date: Thu Mar 13 14:37:02 2025 +0100
[cbrtf] fixed undefined behavior
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list