http://bugs.winehq.org/show_bug.cgi?id=36153
--- Comment #10 from Piotr Caban piotr.caban@gmail.com --- The game is using qsort in broken way. It uses comparator that always returns 1 and expects that data is reordered in some specific way. In order to fix it wine's qsort implementation needs to call comparator in the same way as native does.
The way comparator is called is not preserved between different versions of msvcrXX.dll (I've checked only msvcrt.dll and msvcr100.dll).
It looks like msvcrt uses very similar sorting algorithm as glibc. It uses qsort (pivot element is selected from 3 elements) and falls back to insertion sort on small portions of table (with less than 9 elements).
Adding something like this in qsort_s fixes Borderlands 2 for me: /* Borderlands 2 depends on comparator calling order for small tables */ if (nmemb <= 8) { MSVCRT_size_t e, i; char *max, *p, tmp;
for(e=nmemb; e>1; e--) { max = base; for(i=1; i<e; i++) { p = (char*)base + i*size; if(compar(context, p, max) > 0) max = p; }
if(p != max) { for(i=size; i; i--) { tmp = *max; *max++ = *p; *p++ = tmp; } } }
return; }