[PATCH:libX11 10/22] miRegionCopy(): handle realloc failure better

Alan Coopersmith alan.coopersmith at oracle.com
Mon Aug 12 00:04:01 PDT 2013


Zero out the region size when freeing the region so callers don't think
there's anything there.   (Pointer is already set to NULL from the realloc
result itself.)  Return 0 to the callers, and have them cascade that back
to their callers to indicate failure, instead of their usual return value
of 1 on success.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/Region.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Region.c b/src/Region.c
index d3d431a..8946268 100644
--- a/src/Region.c
+++ b/src/Region.c
@@ -507,7 +507,7 @@ XIntersectRegion(
     return 1;
 }
 
-static void
+static int
 miRegionCopy(
     register Region dstrgn,
     register Region rgn)
@@ -525,7 +525,8 @@ miRegionCopy(
 					 rgn->numRects * (sizeof(BOX)));
 		if (! dstrgn->rects) {
 		    Xfree(prevRects);
-		    return;
+		    dstrgn->size = 0;
+		    return 0;
 		}
             }
             dstrgn->size = rgn->numRects;
@@ -539,6 +540,7 @@ miRegionCopy(
 	memcpy((char *) dstrgn->rects, (char *) rgn->rects,
 	       (int) (rgn->numRects * sizeof(BOX)));
     }
+    return 1;
 }
 
 /*======================================================================
@@ -1150,7 +1152,7 @@ XUnionRegion(
     if ( (reg1 == reg2) || (!(reg1->numRects)) )
     {
         if (newReg != reg2)
-            miRegionCopy(newReg, reg2);
+            return miRegionCopy(newReg, reg2);
         return 1;
     }
 
@@ -1160,7 +1162,7 @@ XUnionRegion(
     if (!(reg2->numRects))
     {
         if (newReg != reg1)
-            miRegionCopy(newReg, reg1);
+            return miRegionCopy(newReg, reg1);
         return 1;
     }
 
@@ -1174,7 +1176,7 @@ XUnionRegion(
 	(reg1->extents.y2 >= reg2->extents.y2))
     {
         if (newReg != reg1)
-            miRegionCopy(newReg, reg1);
+            return miRegionCopy(newReg, reg1);
         return 1;
     }
 
@@ -1188,7 +1190,7 @@ XUnionRegion(
 	(reg2->extents.y2 >= reg1->extents.y2))
     {
         if (newReg != reg2)
-            miRegionCopy(newReg, reg2);
+            return miRegionCopy(newReg, reg2);
         return 1;
     }
 
@@ -1429,8 +1431,7 @@ XSubtractRegion(
     if ( (!(regM->numRects)) || (!(regS->numRects))  ||
 	(!EXTENTCHECK(&regM->extents, &regS->extents)) )
     {
-	miRegionCopy(regD, regM);
-        return 1;
+	return miRegionCopy(regD, regM);
     }
 
     miRegionOp (regD, regM, regS, miSubtractO,
-- 
1.7.9.2



More information about the xorg-devel mailing list