Commit a8bba784 authored by Guy L. Albertelli's avatar Guy L. Albertelli Committed by Alexandre Julliard

Fix problems in DPA_Merge exposed by previous code cleanup.

parent e3d9406f
......@@ -198,7 +198,7 @@ DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
{
INT nCount;
LPVOID *pWork1, *pWork2;
INT nResult;
INT nResult, i;
INT nIndex;
TRACE("%p %p %08lx %p %p %08lx)\n",
......@@ -216,7 +216,7 @@ DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
if (IsBadCodePtr ((FARPROC)pfnMerge))
return FALSE;
if (dwFlags & DPAM_SORT) {
if (!(dwFlags & DPAM_NOSORT)) {
TRACE("sorting dpa's!\n");
if (hdpa1->nItemCount > 0)
DPA_Sort (hdpa1, pfnCompare, lParam);
......@@ -243,7 +243,23 @@ DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
do
{
if (nIndex < 0) break;
if (nIndex < 0) {
if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
/* Now insert the remaining new items into DPA 1 */
TRACE("%d items to be inserted at start of DPA 1\n",
nCount+1);
for (i=nCount; i>=0; i--) {
PVOID ptr;
ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
if (!ptr)
return FALSE;
DPA_InsertPtr (hdpa1, 0, ptr);
pWork2--;
}
}
break;
}
nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
nResult, nIndex, nCount);
......@@ -262,10 +278,12 @@ DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
nIndex--;
pWork1--;
}
else if (nResult < 0)
else if (nResult > 0)
{
if (!(dwFlags & 8))
/* item in DPA 1 missing from DPA 2 */
if (dwFlags & DPAM_DELETE)
{
/* Now delete the extra item in DPA1 */
PVOID ptr;
ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
......@@ -277,14 +295,16 @@ DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
}
else
{
if (!(dwFlags & 4))
/* new item in DPA 2 */
if (dwFlags & DPAM_INSERT)
{
/* Now insert the new item in DPA 1 */
PVOID ptr;
ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
if (!ptr)
return FALSE;
DPA_InsertPtr (hdpa1, nIndex, ptr);
DPA_InsertPtr (hdpa1, nIndex+1, ptr);
}
nCount--;
pWork2--;
......
......@@ -4057,7 +4057,9 @@ BOOL WINAPI DPA_Sort (const HDPA, PFNDPACOMPARE, LPARAM);
INT WINAPI DPA_Search (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
#define DPAM_SORT 0x0001
#define DPAM_NOSORT 0x0001
#define DPAM_INSERT 0x0004
#define DPAM_DELETE 0x0008
typedef PVOID (CALLBACK *PFNDPAMERGE)(DWORD,PVOID,PVOID,LPARAM);
BOOL WINAPI DPA_Merge (const HDPA, const HDPA, DWORD, PFNDPACOMPARE, PFNDPAMERGE, LPARAM);
......
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