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@
-/* $OpenBSD: bsearch.c,v 1.8 2016/10/22 19:19:34 tb Exp $ */
+/* $OpenBSD: bsearch.c,v 1.9 2021/12/02 20:58:01 cheloha Exp $ */
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
int (*compar)(const void *, const void *))
{
const char *base = base0;
- int lim, cmp;
const void *p;
+ size_t lim;
+ int cmp;
for (lim = nmemb; lim != 0; lim >>= 1) {
p = base + (lim >> 1) * size;