Resize dynamic pointer array more carefully when adding new entries.

diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index 2b1ddfa..a1eb807 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -1957,11 +1957,7 @@
 
     if (hdpa->nItemCount <= i) {
 	/* within the old array */
-	if (hdpa->nMaxCount > i) {
-	    /* within the allocated space, set a new boundary */
-	    hdpa->nItemCount = i+1;
-	}
-	else {
+	if (hdpa->nMaxCount <= i) {
 	    /* resize the block of memory */
 	    INT nNewItems =
 		hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
@@ -1972,9 +1968,10 @@
 	    if (!lpTemp)
 		return FALSE;
 
-	    hdpa->nItemCount = nNewItems;
+	    hdpa->nMaxCount = nNewItems;
 	    hdpa->ptrs = lpTemp;
 	}
+        hdpa->nItemCount = i+1;
     }
 
     /* put the new entry in */