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

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 12 Aug 2025 10:00:16 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288778

--- Comment #7 from commit-hook@FreeBSD.org ---
A commit in branch main references this bug:

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

commit d180086e6eae2e152e803ed6cf13775a7c006dc7
Author:     Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2025-08-12 04:26:29 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-08-12 05:31:03 +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

 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.