HomeFreeBSD

libc qsort(3): Eliminate ambiguous sign comparison

Description

libc qsort(3): Eliminate ambiguous sign comparison

The left side of the MIN() expression is the (signed) result of pointer
subtraction (ptrdiff_t). The right hand side is the also the (signed)
result of pointer subtraction, additionally subtracting the element size
('es'), which is unsigned size_t. This coerces the right-hand
expression into an unsigned value. MIN(signed, unsigned) triggers
-Wsign-compare.

Sorting elements of size greater than SSIZE_MAX is nonsensical, so we
can instead treat the element size as ssize_t, leaving the right-hand
result the same signedness as the left.

Reviewed by: arichardson, kib
Differential Revision: https://reviews.freebsd.org/D31292

Details

Provenance
cemAuthored on Jul 23 2021, 6:04 PM
Reviewer
arichardson
Differential Revision
D31292: libc qsort(3): Eliminate ambiguous sign comparison
Parents
rGe3707726c168: kern: remove deprecated makesyscalls.sh
Branches
Unknown
Tags
Unknown