bsearch(3): support arrays with more than INT_MAX elements
authorcheloha <cheloha@openbsd.org>
Thu, 2 Dec 2021 20:58:01 +0000 (20:58 +0000)
committercheloha <cheloha@openbsd.org>
Thu, 2 Dec 2021 20:58:01 +0000 (20:58 +0000)
commitd10db4f7696863b7a3e27722ecb8083ffe76d3c4
tree27986834fbca7d3a406522c874e2e2e14d6af39e
parentda3b7e6e421a20f0e536819cea00fc8bdd118137
bsearch(3): support arrays with more than INT_MAX elements

The "lim" variable needs to be a size_t to match nmemb, otherwise we
get undefined behavior when nmemb exceeds INT_MAX.

Prompted by a blog post by Joshua Bloch:

https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html

Fixed by Chris Torek a long time ago:

https://svnweb.freebsd.org/csrg/lib/libc/stdlib/bsearch.c?revision=51742&view=markup

ok millert@
lib/libc/stdlib/bsearch.c