]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB on cospif (BZ 32923)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 25 Apr 2025 20:54:27 +0000 (17:54 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 29 Apr 2025 18:20:16 +0000 (15:20 -0300)
The left shift overflows for 'int', use uint32_t instead.  It syncs
with CORE-MATH commit bbfabd993a71b049c210b0febfd06d18369fadc1.

Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
sysdeps/ieee754/flt-32/s_cospif.c

index 1e838037e115623539cc800b97ac0bffae7b2fc4..eb4a10f57f9520a53554aef12f750b9bea776c3d 100644 (file)
@@ -3,7 +3,7 @@
 Copyright (c) 2022-2025 Alexei Sibidanov.
 
 The original version of this file was copied from the CORE-MATH
-project (src/binary32/cospi/cospif.c, revision f786e13).
+project (src/binary32/cospi/cospif.c, revision bbfabd99).
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -58,10 +58,10 @@ __cospif (float x)
     {
       if (__glibc_unlikely (p > 63))
        return 1.0f;
-      int32_t iq = m << (p - 32);
+      int32_t iq = (uint32_t)m << (p - 32);
       return S[(iq + 32) & 127];
     }
-  int32_t k = m << p;
+  int32_t k = (uint32_t)m << p;
   if (__glibc_unlikely (k == 0))
     {
       int32_t iq = m >> (32 - p);