The listview wine bug 56140 is caused by passing the incorrect index to the LISTVIEW_SortItems callers custom compare function.
From: Jacob Czekalla jczekalla@codeweavers.com
--- dlls/comctl32/listview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index c82473b6205..0302e3e19a0 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -9396,7 +9396,7 @@ static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, if (infoPtr->nFocusedItem >= 0) focusedItem = DPA_GetPtr(infoPtr->hdpaItems, infoPtr->nFocusedItem);
- context.items = hdpaItems; + context.items = infoPtr->hdpaItems; context.compare_func = pfnCompare; context.lParam = lParamSort; if (IsEx)
Would you mind adding a `Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56140%60 into the comment?
To explain, the callback function takes two indices, which are relative to the original (unsorted) array. The indices are calculated in `LISTVIEW_CallBackCompare/Ex`, finding the position of the items in `context->items`. So if we need to pass the original array here, otherwise we get messed up indices. Right?
On Fri Jul 26 12:45:53 2024 +0000, Fabian Maurer wrote:
Would you mind adding a `Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56140%60 into the comment? To explain, the callback function takes two indices, which are relative to the original (unsorted) array. The indices are calculated in `LISTVIEW_CallBackCompare/Ex`, finding the position of the items in `context->items`. So if we need to pass the original array here, otherwise we get messed up indices. Right?
Yes. If we pass the copied array indices, which are different because of the sorting, the caller is going to use those indices for their unsorted array which don't match.
Could you please add some tests?