From 6296f798861f4c0af4a1397ca2191e4311c1d217 Mon Sep 17 00:00:00 2001 From: David Reveman Date: Wed, 31 May 2006 11:23:37 +0000 Subject: [PATCH] Fix integer overflow issue --- ChangeLog | 4 ++ hw/xgl/xglfill.c | 176 +++++++++++++++++++++++++++-------------------- 2 files changed, 104 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74e53478c..9a3d0ed35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-05-31 David Reveman + + * hw/xgl/xglfill.c: Fix integer overflow issue. + 2006-05-30 David Reveman * hw/xgl/xglfill.c (xglFillSegment): Fix typo that caused some diff --git a/hw/xgl/xglfill.c b/hw/xgl/xglfill.c index 51f4d801b..a2957b2f0 100644 --- a/hw/xgl/xglfill.c +++ b/hw/xgl/xglfill.c @@ -172,6 +172,7 @@ xglFillRect (DrawablePtr pDrawable, RegionPtr pClip = pGC->pCompositeClip; BoxPtr pClipBox; BoxPtr pExtent = REGION_EXTENTS (pGC->pScreen, pClip); + int fullX1, fullX2, fullY1, fullY2; BoxRec part, full; BoxPtr heapBox = NULL; BoxRec stackBox[N_STACK_BOX]; @@ -181,21 +182,26 @@ xglFillRect (DrawablePtr pDrawable, while (nrect--) { - full.x1 = prect->x + pDrawable->x; - full.y1 = prect->y + pDrawable->y; - full.x2 = full.x1 + (int) prect->width; - full.y2 = full.y1 + (int) prect->height; + fullX1 = prect->x + pDrawable->x; + fullY1 = prect->y + pDrawable->y; + fullX2 = fullX1 + (int) prect->width; + fullY2 = fullY1 + (int) prect->height; prect++; - if (full.x1 < pExtent->x1) - full.x1 = pExtent->x1; - if (full.y1 < pExtent->y1) - full.y1 = pExtent->y1; - if (full.x2 > pExtent->x2) - full.x2 = pExtent->x2; - if (full.y2 > pExtent->y2) - full.y2 = pExtent->y2; + if (fullX1 < pExtent->x1) + fullX1 = pExtent->x1; + if (fullY1 < pExtent->y1) + fullY1 = pExtent->y1; + if (fullX2 > pExtent->x2) + fullX2 = pExtent->x2; + if (fullY2 > pExtent->y2) + fullY2 = pExtent->y2; + + full.x1 = fullX1; + full.y1 = fullY1; + full.x2 = fullX2; + full.y2 = fullY2; if (full.x1 >= full.x2 || full.y1 >= full.y2) continue; @@ -246,6 +252,7 @@ xglFillSpan (DrawablePtr pDrawable, RegionPtr pClip = pGC->pCompositeClip; BoxPtr pClipBox; BoxPtr pExtent = REGION_EXTENTS (pGC->pScreen, pClip); + int fullX1, fullX2, fullY1, fullY2; BoxRec part, full; BoxPtr heapBox = NULL; BoxRec stackBox[N_STACK_BOX]; @@ -255,22 +262,27 @@ xglFillSpan (DrawablePtr pDrawable, while (n--) { - full.x1 = ppt->x; - full.y1 = ppt->y; - full.x2 = full.x1 + *pwidth; - full.y2 = full.y1 + 1; + fullX1 = ppt->x; + fullY1 = ppt->y; + fullX2 = fullX1 + *pwidth; + fullY2 = fullY1 + 1; pwidth++; ppt++; - if (full.x1 < pExtent->x1) - full.x1 = pExtent->x1; - if (full.y1 < pExtent->y1) - full.y1 = pExtent->y1; - if (full.x2 > pExtent->x2) - full.x2 = pExtent->x2; - if (full.y2 > pExtent->y2) - full.y2 = pExtent->y2; + if (fullX1 < pExtent->x1) + fullX1 = pExtent->x1; + if (fullY1 < pExtent->y1) + fullY1 = pExtent->y1; + if (fullX2 > pExtent->x2) + fullX2 = pExtent->x2; + if (fullY2 > pExtent->y2) + fullY2 = pExtent->y2; + + full.x1 = fullX1; + full.y1 = fullY1; + full.x2 = fullX2; + full.y2 = fullY2; if (full.x1 >= full.x2 || full.y1 >= full.y2) continue; @@ -373,6 +385,7 @@ xglFillLine (DrawablePtr pDrawable, if (horizontalAndVertical) { BoxPtr pClipBox; + int fullX1, fullX2, fullY1, fullY2; BoxRec part, full; BoxPtr heapBox = NULL; BoxRec stackBox[N_STACK_BOX]; @@ -403,49 +416,49 @@ xglFillLine (DrawablePtr pDrawable, { if (dx > 0) { - full.x1 = pt.x + pDrawable->x; + fullX1 = pt.x + pDrawable->x; if (npt || coincidentEndpoints) - full.x2 = full.x1 + dx; + fullX2 = fullX1 + dx; else - full.x2 = full.x1 + dx + 1; + fullX2 = fullX1 + dx + 1; } else { - full.x2 = pt.x + pDrawable->x + 1; + fullX2 = pt.x + pDrawable->x + 1; if (npt || coincidentEndpoints) - full.x1 = full.x2 + dx; + fullX1 = fullX2 + dx; else - full.x1 = full.x2 + dx - 1; + fullX1 = fullX2 + dx - 1; } - full.y1 = pt.y + pDrawable->y; - full.y2 = full.y1 + 1; + fullY1 = pt.y + pDrawable->y; + fullY2 = fullY1 + 1; } else { if (dy > 0) { - full.y1 = pt.y + pDrawable->y; + fullY1 = pt.y + pDrawable->y; if (npt || coincidentEndpoints) - full.y2 = full.y1 + dy; + fullY2 = fullY1 + dy; else - full.y2 = full.y1 + dy + 1; + fullY2 = fullY1 + dy + 1; } else { - full.y2 = pt.y + pDrawable->y + 1; + fullY2 = pt.y + pDrawable->y + 1; if (npt || coincidentEndpoints) - full.y1 = full.y2 + dy; + fullY1 = fullY2 + dy; else - full.y1 = full.y2 + dy - 1; + fullY1 = fullY2 + dy - 1; } - full.x1 = pt.x + pDrawable->x; - full.x2 = full.x1 + 1; + fullX1 = pt.x + pDrawable->x; + fullX2 = fullX1 + 1; } pt.x += dx; @@ -453,14 +466,19 @@ xglFillLine (DrawablePtr pDrawable, ppt++; - if (full.x1 < pExtent->x1) - full.x1 = pExtent->x1; - if (full.y1 < pExtent->y1) - full.y1 = pExtent->y1; - if (full.x2 > pExtent->x2) - full.x2 = pExtent->x2; - if (full.y2 > pExtent->y2) - full.y2 = pExtent->y2; + if (fullX1 < pExtent->x1) + fullX1 = pExtent->x1; + if (fullY1 < pExtent->y1) + fullY1 = pExtent->y1; + if (fullX2 > pExtent->x2) + fullX2 = pExtent->x2; + if (fullY2 > pExtent->y2) + fullY2 = pExtent->y2; + + full.x1 = fullX1; + full.y1 = fullY1; + full.x2 = fullX2; + full.y2 = fullY2; if (full.x1 >= full.x2 || full.y1 >= full.y2) continue; @@ -570,6 +588,7 @@ xglFillSegment (DrawablePtr pDrawable, if (horizontalAndVertical) { BoxPtr pClipBox; + int fullX1, fullX2, fullY1, fullY2; BoxRec part, full; BoxPtr heapBox = NULL; BoxRec stackBox[N_STACK_BOX]; @@ -583,57 +602,62 @@ xglFillSegment (DrawablePtr pDrawable, { if (pSegInit->x1 < pSegInit->x2) { - full.x1 = pSegInit->x1; - full.x2 = pSegInit->x2; + fullX1 = pSegInit->x1; + fullX2 = pSegInit->x2; if (pGC->capStyle != CapNotLast) - full.x2++; + fullX2++; } else { - full.x1 = pSegInit->x2; - full.x2 = pSegInit->x1 + 1; + fullX1 = pSegInit->x2; + fullX2 = pSegInit->x1 + 1; if (pGC->capStyle == CapNotLast) - full.x1++; + fullX1++; } - full.x1 += pDrawable->x; - full.x2 += pDrawable->x; - full.y1 = pSegInit->y1 + pDrawable->y; - full.y2 = full.y1 + 1; + fullX1 += pDrawable->x; + fullX2 += pDrawable->x; + fullY1 = pSegInit->y1 + pDrawable->y; + fullY2 = fullY1 + 1; } else { if (pSegInit->y1 < pSegInit->y2) { - full.y1 = pSegInit->y1; - full.y2 = pSegInit->y2; + fullY1 = pSegInit->y1; + fullY2 = pSegInit->y2; if (pGC->capStyle != CapNotLast) - full.y2++; + fullY2++; } else { - full.y1 = pSegInit->y2; - full.y2 = pSegInit->y1 + 1; + fullY1 = pSegInit->y2; + fullY2 = pSegInit->y1 + 1; if (pGC->capStyle == CapNotLast) - full.y1++; + fullY1++; } - full.y1 += pDrawable->y; - full.y2 += pDrawable->y; - full.x1 = pSegInit->x1 + pDrawable->x; - full.x2 = full.x1 + 1; + fullY1 += pDrawable->y; + fullY2 += pDrawable->y; + fullX1 = pSegInit->x1 + pDrawable->x; + fullX2 = fullX1 + 1; } pSegInit++; - if (full.x1 < pExtent->x1) - full.x1 = pExtent->x1; - if (full.y1 < pExtent->y1) - full.y1 = pExtent->y1; - if (full.x2 > pExtent->x2) - full.x2 = pExtent->x2; - if (full.y2 > pExtent->y2) - full.y2 = pExtent->y2; + if (fullX1 < pExtent->x1) + fullX1 = pExtent->x1; + if (fullY1 < pExtent->y1) + fullY1 = pExtent->y1; + if (fullX2 > pExtent->x2) + fullX2 = pExtent->x2; + if (fullY2 > pExtent->y2) + fullY2 = pExtent->y2; + + full.x1 = fullX1; + full.y1 = fullY1; + full.x2 = fullX2; + full.y2 = fullY2; if (full.x1 >= full.x2 || full.y1 >= full.y2) continue;