aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/X11/Region.c
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-10-19 22:15:01 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-10-19 22:15:01 +0200
commit70ac75f4ab184c21d11b9840a47362610aaef481 (patch)
tree183b9ec7e6897fb2cea7296b461a35ca93dfce6e /nx-X11/lib/X11/Region.c
parent6c303d9e4ffd162b8c7f59a4b135e592d923a656 (diff)
parent70e9d346fe34af127d2c827c3678e53d0f4312ae (diff)
downloadnx-libs-70ac75f4ab184c21d11b9840a47362610aaef481.tar.gz
nx-libs-70ac75f4ab184c21d11b9840a47362610aaef481.tar.bz2
nx-libs-70ac75f4ab184c21d11b9840a47362610aaef481.zip
Merge branch 'uli42-pr/libX11_further_backports' into 3.6.x
Attributes GH PR #222: https://github.com/ArcticaProject/nx-libs/pull/222
Diffstat (limited to 'nx-X11/lib/X11/Region.c')
-rw-r--r--nx-X11/lib/X11/Region.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c
index 5ce276279..28fa3e416 100644
--- a/nx-X11/lib/X11/Region.c
+++ b/nx-X11/lib/X11/Region.c
@@ -139,10 +139,10 @@ XCreateRegion(void)
{
Region temp;
- if (! (temp = ( Region )Xmalloc( (unsigned) sizeof( REGION ))))
+ if (! (temp = Xmalloc(sizeof( REGION ))))
return (Region) NULL;
- if (! (temp->rects = ( BOX * )Xmalloc( (unsigned) sizeof( BOX )))) {
- Xfree((char *) temp);
+ if (! (temp->rects = Xmalloc(sizeof( BOX )))) {
+ Xfree(temp);
return (Region) NULL;
}
temp->numRects = 0;
@@ -384,7 +384,12 @@ XShrinkRegion(
int grow;
if (!dx && !dy) return 0;
- if ((! (s = XCreateRegion())) || (! (t = XCreateRegion()))) return 0;
+ if (! (s = XCreateRegion()) )
+ return 0;
+ if (! (t = XCreateRegion()) ) {
+ XDestroyRegion(s);
+ return 0;
+ }
if ((grow = (dx < 0))) dx = -dx;
if (dx) Compress(r, s, t, (unsigned) 2*dx, TRUE, grow);
if ((grow = (dy < 0))) dy = -dy;
@@ -502,7 +507,7 @@ XIntersectRegion(
return 1;
}
-static void
+static int
miRegionCopy(
register Region dstrgn,
register Region rgn)
@@ -516,11 +521,12 @@ miRegionCopy(
{
BOX *prevRects = dstrgn->rects;
- if (! (dstrgn->rects = (BOX *)
- Xrealloc((char *) dstrgn->rects,
- (unsigned) rgn->numRects * (sizeof(BOX))))) {
+ dstrgn->rects = Xrealloc(dstrgn->rects,
+ rgn->numRects * (sizeof(BOX)));
+ if (! dstrgn->rects) {
Xfree(prevRects);
- return;
+ dstrgn->size = 0;
+ return 0;
}
}
dstrgn->size = rgn->numRects;
@@ -534,6 +540,7 @@ miRegionCopy(
memcpy((char *) dstrgn->rects, (char *) rgn->rects,
(int) (rgn->numRects * sizeof(BOX)));
}
+ return 1;
}
/*======================================================================
@@ -783,8 +790,7 @@ miRegionOp(
*/
newReg->size = max(reg1->numRects,reg2->numRects) * 2;
- if (! (newReg->rects = (BoxPtr)
- Xmalloc ((unsigned) (sizeof(BoxRec) * newReg->size)))) {
+ if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) {
newReg->size = 0;
return;
}
@@ -974,11 +980,12 @@ miRegionOp(
if (REGION_NOT_EMPTY(newReg))
{
BoxPtr prev_rects = newReg->rects;
- newReg->size = newReg->numRects;
- newReg->rects = (BoxPtr) Xrealloc ((char *) newReg->rects,
- (unsigned) (sizeof(BoxRec) * newReg->size));
+ newReg->rects = Xrealloc (newReg->rects,
+ sizeof(BoxRec) * newReg->numRects);
if (! newReg->rects)
newReg->rects = prev_rects;
+ else
+ newReg->size = newReg->numRects;
}
else
{
@@ -987,11 +994,11 @@ miRegionOp(
* the region is empty
*/
newReg->size = 1;
- Xfree((char *) newReg->rects);
- newReg->rects = (BoxPtr) Xmalloc(sizeof(BoxRec));
+ Xfree(newReg->rects);
+ newReg->rects = Xmalloc(sizeof(BoxRec));
}
}
- Xfree ((char *) oldRects);
+ Xfree (oldRects);
return;
}
@@ -1146,7 +1153,7 @@ XUnionRegion(
if ( (reg1 == reg2) || (!(reg1->numRects)) )
{
if (newReg != reg2)
- miRegionCopy(newReg, reg2);
+ return miRegionCopy(newReg, reg2);
return 1;
}
@@ -1156,7 +1163,7 @@ XUnionRegion(
if (!(reg2->numRects))
{
if (newReg != reg1)
- miRegionCopy(newReg, reg1);
+ return miRegionCopy(newReg, reg1);
return 1;
}
@@ -1170,7 +1177,7 @@ XUnionRegion(
(reg1->extents.y2 >= reg2->extents.y2))
{
if (newReg != reg1)
- miRegionCopy(newReg, reg1);
+ return miRegionCopy(newReg, reg1);
return 1;
}
@@ -1184,7 +1191,7 @@ XUnionRegion(
(reg2->extents.y2 >= reg1->extents.y2))
{
if (newReg != reg2)
- miRegionCopy(newReg, reg2);
+ return miRegionCopy(newReg, reg2);
return 1;
}
@@ -1425,8 +1432,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,
@@ -1448,8 +1454,12 @@ XXorRegion(Region sra, Region srb, Region dr)
{
Region tra, trb;
- if ((! (tra = XCreateRegion())) || (! (trb = XCreateRegion())))
+ if (! (tra = XCreateRegion()) )
return 0;
+ if (! (trb = XCreateRegion()) ) {
+ XDestroyRegion(tra);
+ return 0;
+ }
(void) XSubtractRegion(sra,srb,tra);
(void) XSubtractRegion(srb,sra,trb);
(void) XUnionRegion(tra,trb,dr);