[Bug 288778] [libm] Fix undefined behavior of a left shifted of a signed integer

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 21 Aug 2025 10:43:41 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288778

--- Comment #9 from commit-hook@FreeBSD.org ---
A commit in branch stable/13 references this bug:

URL:
https://cgit.FreeBSD.org/src/commit/?id=94b09b2f3440b16b58dd744fcaa73229f6503c10

commit 94b09b2f3440b16b58dd744fcaa73229f6503c10
Author:     Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2025-08-12 04:26:29 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-08-21 10:41:41 +0000

    [libm] Fix undefined behavior of a left shifted of a signed integer

    The patch fixes a few instances of left shifts on
    signed integer entities.  A 'static inline' helper function
    'subnormal_ilogb()' has been added to math_private.h.  This
    function is then used e_fmod.c, s_ilogb(), and s_remquo.c.

    The change in s_remquo.c has only been compile tested.

    The change to e_fmod.c has been test on over 3 billion pairs
    of subnormal numbers where testing included x > y and x < y
    pairs.  The test compared the output from fmod() with the
    output from mpfr_fmod() from MPFR.  There were no difference.

    The change to s_ilogb() has had limited testing where its
    output was compared against frexp().  In this testing, no
    differences in output were detected.

    PR:     288778
    MFC after:      1 week

    (cherry picked from commit d180086e6eae2e152e803ed6cf13775a7c006dc7)

 lib/msun/src/e_fmod.c       | 30 ++++++++++++------------------
 lib/msun/src/math_private.h | 21 +++++++++++++++++++++
 lib/msun/src/s_ilogb.c      | 13 +++++--------
 lib/msun/src/s_remquo.c     | 30 ++++++++++++------------------
 4 files changed, 50 insertions(+), 44 deletions(-)

-- 
You are receiving this mail because:
You are the assignee for the bug.