Commit 8436b58e authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Use size_t to store indexes in qsort.

It also avoids potential overflow while computing median position (found by Frédéric Delanoy).
parent 40067dd0
......@@ -262,8 +262,9 @@ static void small_sort(void *base, MSVCRT_size_t nmemb, MSVCRT_size_t size,
static void quick_sort(void *base, MSVCRT_size_t nmemb, MSVCRT_size_t size,
int (CDECL *compar)(void *, const void *, const void *), void *context)
{
int stack_lo[8*sizeof(MSVCRT_size_t)], stack_hi[8*sizeof(MSVCRT_size_t)], stack_pos;
int beg, end, lo, hi, med;
MSVCRT_size_t stack_lo[8*sizeof(MSVCRT_size_t)], stack_hi[8*sizeof(MSVCRT_size_t)];
MSVCRT_size_t beg, end, lo, hi, med;
int stack_pos;
stack_pos = 0;
stack_lo[stack_pos] = 0;
......@@ -281,7 +282,7 @@ static void quick_sort(void *base, MSVCRT_size_t nmemb, MSVCRT_size_t size,
lo = beg;
hi = end;
med = (hi+lo+1)/2;
med = lo + (hi-lo+1)/2;
if(compar(context, X(lo), X(med)) > 0)
swap(X(lo), X(med), size);
if(compar(context, X(lo), X(hi)) > 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment