ntdll: Avoid potential integer overflow when computing median position in bsearch.

Frédéric Delanoy frederic.delanoy at gmail.com
Thu Jul 3 05:19:25 CDT 2014


Note there are still potential overflows in various other custom binary searches in the code, but
these are a lot less likely to cause a problem.
---
 dlls/ntdll/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dlls/ntdll/misc.c b/dlls/ntdll/misc.c
index 659d504..ad1b43b 100644
--- a/dlls/ntdll/misc.c
+++ b/dlls/ntdll/misc.c
@@ -299,7 +299,7 @@ NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
 
     while (min <= max)
     {
-        ssize_t cursor = (min + max) / 2;
+        ssize_t cursor = min + (max - min) / 2;
         int ret = compar(key,(const char *)base+(cursor*size));
         if (!ret)
             return (char*)base+(cursor*size);
-- 
2.0.1




More information about the wine-patches mailing list