comctl32: Fix warn:dpa:not enough pointers in listview.c:ranges_assert

Peter Schauer peterschauer at gmx.net
Fri Feb 20 10:48:24 CST 2009


This fixes bug 17478: http://bugs.winehq.org/show_bug.cgi?id=17478
a small glitch in listview.c which causes a

warn:dpa:not enough pointers in array (0 vs 0)

warning from DPA_GetPtr.

It happens when LISTVIEW_DeselectAllSkipItem creates an empty range
and then calls ranges_additem to add one item to the range.
ranges_additem calls ranges_add which calls
ranges_check(ranges, "before add"), effectively calling ranges_assert.
And ranges_assert calls DPA_GetPtr(ranges->hdpa, 0), accessing the
first element in the empty range, which triggers the warning.

Here is a patch without whitespace changes to make it more readable:

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index b8545fd..578482b 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -2605,8 +2605,9 @@ static void ranges_assert(RANGES ranges, LPCSTR desc, const char *func, int line
     assert (ranges);
     assert (DPA_GetPtrCount(ranges->hdpa) >= 0);
     ranges_dump(ranges);
-    prev = DPA_GetPtr(ranges->hdpa, 0);
     if (DPA_GetPtrCount(ranges->hdpa) > 0)
+    {
+	prev = DPA_GetPtr(ranges->hdpa, 0);
 	assert (prev->lower >= 0 && prev->lower < prev->upper);
     for (i = 1; i < DPA_GetPtrCount(ranges->hdpa); i++)
     {
@@ -2615,6 +2616,7 @@ static void ranges_assert(RANGES ranges, LPCSTR desc, const char *func, int line
 	assert (curr->lower < curr->upper);
 	prev = curr;
     }
+    }
     TRACE("--- Done checking---\n");
 }
 

and the proper patch with whitespace changes:

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index b8545fd..578482b 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -2605,15 +2605,17 @@ static void ranges_assert(RANGES ranges, LPCSTR desc, const char *func, int line
     assert (ranges);
     assert (DPA_GetPtrCount(ranges->hdpa) >= 0);
     ranges_dump(ranges);
-    prev = DPA_GetPtr(ranges->hdpa, 0);
     if (DPA_GetPtrCount(ranges->hdpa) > 0)
-	assert (prev->lower >= 0 && prev->lower < prev->upper);
-    for (i = 1; i < DPA_GetPtrCount(ranges->hdpa); i++)
     {
-        curr = DPA_GetPtr(ranges->hdpa, i);
-	assert (prev->upper <= curr->lower);
-	assert (curr->lower < curr->upper);
-	prev = curr;
+	prev = DPA_GetPtr(ranges->hdpa, 0);
+	assert (prev->lower >= 0 && prev->lower < prev->upper);
+	for (i = 1; i < DPA_GetPtrCount(ranges->hdpa); i++)
+	{
+	    curr = DPA_GetPtr(ranges->hdpa, i);
+	    assert (prev->upper <= curr->lower);
+	    assert (curr->lower < curr->upper);
+	    prev = curr;
+	}
     }
     TRACE("--- Done checking---\n");
 }




More information about the wine-patches mailing list