msvcrt: Use size_t to store indexes in bsearch
Frédéric Delanoy
frederic.delanoy at gmail.com
Fri Jun 20 02:53:54 CDT 2014
Also avoid potential integer overflow when computing median position
---
dlls/msvcrt/misc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/misc.c b/dlls/msvcrt/misc.c
index c07005a..0bcbac3 100644
--- a/dlls/msvcrt/misc.c
+++ b/dlls/msvcrt/misc.c
@@ -131,15 +131,15 @@ void* CDECL MSVCRT_bsearch_s(const void *key, const void *base,
MSVCRT_size_t nmemb, MSVCRT_size_t size,
int (__cdecl *compare)(void *, const void *, const void *), void *ctx)
{
- ssize_t min = 0;
- ssize_t max = nmemb - 1;
+ MSVCRT_size_t min = 0;
+ MSVCRT_size_t max = nmemb - 1;
if (!MSVCRT_CHECK_PMT(size != 0)) return NULL;
if (!MSVCRT_CHECK_PMT(compare != NULL)) return NULL;
while (min <= max)
{
- ssize_t cursor = (min + max) / 2;
+ MSVCRT_size_t cursor = min + (max - min) / 2;
int ret = compare(ctx, key,(const char *)base+(cursor*size));
if (!ret)
return (char*)base+(cursor*size);
--
2.0.0
More information about the wine-patches
mailing list