Validate imagelists #2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A cleaner version, suggested by Dimitrie. Also found a few more places to validate.

Changelog:
Validate imagelists with christmas magic.


Index: dlls/comctl32/imagelist.h
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/imagelist.h,v
retrieving revision 1.3
diff -u -r1.3 imagelist.h
--- dlls/comctl32/imagelist.h	31 May 2002 23:25:44 -0000	1.3
+++ dlls/comctl32/imagelist.h	24 Dec 2002 20:33:47 -0000
@@ -53,6 +53,8 @@
     INT     nOvlIdx[15];
 };
 
+#define IMAGELIST_MAGIC 0x4C4D4948
+
 /* Header used by ImageList_Read() and ImageList_Write() */
 typedef struct _ILHEAD
 {
Index: dlls/comctl32/imagelist.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/imagelist.c,v
retrieving revision 1.68
diff -u -r1.68 imagelist.c
--- dlls/comctl32/imagelist.c	5 Dec 2002 20:33:09 -0000	1.68
+++ dlls/comctl32/imagelist.c	24 Dec 2002 20:33:49 -0000
@@ -76,6 +76,11 @@
 static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, FALSE, 0, FALSE };
 
 
+static inline BOOL is_valid(HIMAGELIST himl)
+{
+    return himl && himl->magic == IMAGELIST_MAGIC;
+}
+
 
 /*************************************************************************
  * IMAGELIST_InternalExpandBitmaps [Internal]
@@ -171,7 +176,7 @@
     HBITMAP hOldBitmapImage, hOldBitmap;
 
     TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
-    if (!himl || !hbmImage)
+    if (!is_valid(himl))
         return -1;
 
     GetObjectA (hbmImage, sizeof(BITMAP), (LPVOID)&bmp);
@@ -283,7 +288,7 @@
     COLORREF bkColor;
 
     TRACE("himl=%p hbitmap=%p clrmask=%lx\n", himl, hBitmap, clrMask);
-    if (himl == NULL)
+    if (!is_valid(himl))
         return -1;
 
     if (!GetObjectA (hBitmap, sizeof(BITMAP), &bmp))
@@ -395,7 +400,7 @@
     TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
 	  dxHotspot, dyHotspot);
 
-    if (himlTrack == NULL)
+    if (!is_valid(himlTrack))
 	return FALSE;
 
     if (InternalDrag.himl)
@@ -467,7 +472,7 @@
 
     TRACE("iDst=%d  iSrc=%d\n", iDst, iSrc);
 
-    if ((himlSrc == NULL) || (himlDst == NULL))
+    if (!is_valid(himlSrc) || !is_valid(himlDst))
 	return FALSE;
     if ((iDst < 0) || (iDst >= himlDst->cCurImage))
 	return FALSE;
@@ -599,6 +604,7 @@
     if (!himl)
         return NULL;
 
+    himl->magic     = IMAGELIST_MAGIC;
     himl->cx        = cx;
     himl->cy        = cy;
     himl->flags     = flags;
@@ -608,6 +614,10 @@
     himl->cCurImage = 0;
     himl->clrFg     = CLR_DEFAULT;
     himl->clrBk     = CLR_NONE;
+    himl->hbmImage  = 0;
+    himl->hbmMask   = 0;
+    himl->hbrBlend25 = 0;
+    himl->hbrBlend50 = 0;
 
     /* initialize overlay mask indices */
     for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
@@ -625,6 +635,7 @@
                         1, himl->uBitsPixel, NULL);
 	if (himl->hbmImage == 0) {
 	    ERR("Error creating image bitmap!\n");
+	    ImageList_Destroy(himl);
 	    return NULL;
 	}
     }
@@ -640,8 +651,7 @@
 					1, 1, NULL);
         if (himl->hbmMask == 0) {
             ERR("Error creating mask bitmap!\n");
-            if (himl->hbmImage)
-                DeleteObject (himl->hbmImage);
+            ImageList_Destroy(himl);
             return NULL;
         }
     }
@@ -678,7 +688,7 @@
 BOOL WINAPI
 ImageList_Destroy (HIMAGELIST himl)
 {
-    if (!himl)
+    if (!is_valid(himl))
 	return FALSE;
 
     /* delete image bitmaps */
@@ -724,7 +734,7 @@
 {
     TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
 
-    if (InternalDrag.himl == NULL)
+    if (!is_valid(InternalDrag.himl))
 	return FALSE;
 
     if (hwndLock)
@@ -846,9 +856,8 @@
 {
     TRACE("(x=%d y=%d)\n", x, y);
 
-    if (!InternalDrag.himl) {
+    if (!is_valid(InternalDrag.himl))
 	return FALSE;
-    }
 
     /* draw/update the drag image */
     if (InternalDrag.bShow) {
@@ -935,6 +944,9 @@
     HDC hdcBg;
     INT x, y;
 
+    if (!is_valid(InternalDrag.himl))
+        return FALSE;
+    
     TRACE("bShow=0x%X!\n", bShow);
 
     /* DragImage is already visible/hidden */
@@ -1084,6 +1096,7 @@
     HIMAGELIST himl;
 
     if (!pimldp || !(himl = pimldp->himl)) return FALSE;
+    if (!is_valid(himl)) return FALSE;
     if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
 
     lx = himl->cx * pimldp->i + pimldp->xBitmap;
@@ -1248,7 +1261,7 @@
     HIMAGELIST himlDst;
     HDC hdcSrc, hdcDst;
 
-    if (himlSrc == NULL) {
+    if (!is_valid(himlSrc)) {
         ERR("Invalid image list handle!\n");
         return NULL;
     }
@@ -1353,7 +1366,7 @@
 HIMAGELIST WINAPI
 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
 {
-    if (InternalDrag.himl) {
+    if (is_valid(InternalDrag.himl)) {
 	if (ppt) {
 	    ppt->x = InternalDrag.x;
 	    ppt->y = InternalDrag.y;
@@ -1407,7 +1420,7 @@
     HBITMAP hOldDstBitmap;
     HDC hdcDst;
 
-    if ((himl == NULL) || (i < 0) || (i >= himl->cCurImage)) return 0;
+    if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
 
     hdcDst = CreateCompatibleDC(0);
 
@@ -1461,7 +1474,7 @@
 BOOL WINAPI
 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
 {
-    if (himl == NULL)
+    if (!is_valid(himl))
 	return FALSE;
     if ((himl->cx <= 0) || (himl->cy <= 0))
 	return FALSE;
@@ -1491,7 +1504,7 @@
 INT WINAPI
 ImageList_GetImageCount (HIMAGELIST himl)
 {
-    if (himl == NULL)
+    if (!is_valid(himl))
 	return 0;
 
     return himl->cCurImage;
@@ -1516,7 +1529,7 @@
 BOOL WINAPI
 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
 {
-    if ((himl == NULL) || (pImageInfo == NULL))
+    if (!is_valid(himl) || (pImageInfo == NULL))
 	return FALSE;
     if ((i < 0) || (i >= himl->cCurImage))
 	return FALSE;
@@ -1554,7 +1567,7 @@
 BOOL WINAPI
 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
 {
-    if ((himl == NULL) || (lpRect == NULL))
+    if (!is_valid(himl) || (lpRect == NULL))
 	return FALSE;
     if ((i < 0) || (i >= himl->cCurImage))
 	return FALSE;
@@ -1625,6 +1638,10 @@
 
         himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
                                  nImageCount, cGrow);
+        if (!himl) {
+            DeleteObject (handle);
+            return NULL;
+        }
         ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
     }
     else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
@@ -1635,6 +1652,12 @@
         GetObjectA (ii.hbmColor, sizeof(BITMAP), (LPVOID)&bmp);
         himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
                                  ILC_MASK | ILC_COLOR, 1, cGrow);
+        if (!himl) {
+            DeleteObject (ii.hbmColor);
+            DeleteObject (ii.hbmMask);
+            DeleteObject (handle);
+            return NULL;
+        }
         ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
         DeleteObject (ii.hbmColor);
         DeleteObject (ii.hbmMask);
@@ -1702,6 +1725,10 @@
 
         himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
                                  nImageCount, cGrow);
+        if (!himl) {
+            DeleteObject (handle);
+            return NULL;
+        }
         ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
     }
     else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
@@ -1712,6 +1739,12 @@
         GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
         himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
                                  ILC_MASK | ILC_COLOR, 1, cGrow);
+        if (!himl) {
+            DeleteObject (ii.hbmColor);
+            DeleteObject (ii.hbmMask);
+            DeleteObject (handle);
+            return NULL;
+        }
         ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
         DeleteObject (ii.hbmColor);
         DeleteObject (ii.hbmMask);
@@ -1755,7 +1788,7 @@
     TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
 	   i2, dx, dy);
 
-    if ((himl1 == NULL) || (himl2 == NULL))
+    if (!is_valid(himl1) || !is_valid(himl2))
 	return NULL;
 
     /* check indices */
@@ -1802,6 +1835,8 @@
     }
 
     himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
+    if (!himlDst)
+        return NULL;
 
     if (himlDst) {
         hdcSrcImage = CreateCompatibleDC (0);
@@ -2072,7 +2107,7 @@
 
     TRACE("(himl=%p i=%d)\n", himl, i);
 
-    if (himl == NULL) {
+    if (!is_valid(himl)) {
         ERR("Invalid image list handle!\n");
         return FALSE;
     }
@@ -2208,7 +2243,7 @@
 
     TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
 
-    if (himl == NULL) {
+    if (!is_valid(himl)) {
         ERR("Invalid image list handle!\n");
         return FALSE;
     }
@@ -2283,7 +2318,7 @@
 
     TRACE("(0x%lx 0x%x %p)\n", (DWORD)himl, i, hIcon);
 
-    if (himl == NULL)
+    if (!is_valid(himl))
 	return -1;
     if ((i >= himl->cMaxImage) || (i < -1))
 	return -1;
@@ -2371,7 +2406,7 @@
 {
     COLORREF clrOldBk;
 
-    if (himl == NULL)
+    if (!is_valid(himl))
 	return CLR_NONE;
 
     clrOldBk = himl->clrBk;
@@ -2409,7 +2444,7 @@
     INT dx, dy;
     BOOL visible;
 
-    if (InternalDrag.himl == NULL)
+    if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
 	return FALSE;
 
     TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
@@ -2526,7 +2561,7 @@
 {
     INT nCount;
 
-    if (!himl)
+    if (!is_valid(himl))
 	return FALSE;
 
     /* remove all images */
@@ -2578,7 +2613,7 @@
 
     TRACE("%p %d\n",himl,iImageCount);
 
-    if (!himl)
+    if (!is_valid(himl))
 	return FALSE;
     if (himl->cCurImage >= iImageCount)
 	return FALSE;
@@ -2672,7 +2707,7 @@
 BOOL WINAPI
 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
 {
-    if (!himl)
+    if (!is_valid(himl))
 	return FALSE;
     if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
 	return FALSE;
@@ -2805,7 +2840,7 @@
     ILHEAD ilHead;
     int i;
 
-    if (!himl)
+    if (!is_valid(himl))
 	return FALSE;
 
     ilHead.usMagic   = (('L' << 8) | 'I');

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux