]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix null pointer subtraction in mergesort()
authorDimitry Andric <dim@FreeBSD.org>
Fri, 27 Aug 2021 17:45:43 +0000 (19:45 +0200)
committerDimitry Andric <dim@FreeBSD.org>
Tue, 31 Aug 2021 19:11:00 +0000 (21:11 +0200)
commita2ddb544867a6100fc4b684772897134511bb72c
tree168b17650e6c139254c33f781101e80627738a80
parentf1a8fe3aed9a513e0ab87055de1442462e7c1e9b
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)
lib/libc/stdlib/merge.c