HomeFreeBSD

Fix null pointer subtraction in mergesort()

Description

Fix null pointer subtraction in mergesort()

Clang 13 produces the following warning for this function:

lib/libc/stdlib/merge.c:137:41: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]

if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE))
                                       ^ ~~~~~~~~~

This is meant to check whether the size and base parameters are aligned
to the size of an int, so use our __is_aligned() macro instead.

Also remove the comment that indicated this "stupid subtraction" was
done to pacify some ancient and unknown Cray compiler, and which has
been there since the BSD 4.4 Lite Lib Sources were imported.

(cherry picked from commit 4e5d32a445f90d37966cd6de571978551654e3f3)

Details

Provenance
dimAuthored on Aug 27 2021, 5:45 PM
Parents
rGd4c7ab9b1d00: pfctl: build fix
Branches
Unknown
Tags
Unknown