Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 400813. Prevent nsRect::Deflate from creating negative-sized rect…
Browse files Browse the repository at this point in the history
…angles. r+sr=mats
  • Loading branch information
Unknown committed Jan 21, 2008
1 parent 315507f commit 10e5914
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions gfx/src/nsRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
#include "nsString.h"
#include "nsIDeviceContext.h"

#ifdef MIN
#undef MIN
#endif

#ifdef MAX
#undef MAX
#endif

#define MIN(a,b)\
((a) < (b) ? (a) : (b))
#define MAX(a,b)\
((a) > (b) ? (a) : (b))

// Containment
PRBool nsRect::Contains(nscoord aX, nscoord aY) const
{
Expand Down Expand Up @@ -85,19 +72,19 @@ PRBool nsRect::IntersectRect(const nsRect &aRect1, const nsRect &aRect2)
nscoord ymost2 = aRect2.YMost();
nscoord temp;

x = MAX(aRect1.x, aRect2.x);
y = MAX(aRect1.y, aRect2.y);
x = PR_MAX(aRect1.x, aRect2.x);
y = PR_MAX(aRect1.y, aRect2.y);

// Compute the destination width
temp = MIN(xmost1, xmost2);
temp = PR_MIN(xmost1, xmost2);
if (temp <= x) {
Empty();
return PR_FALSE;
}
width = temp - x;

// Compute the destination height
temp = MIN(ymost1, ymost2);
temp = PR_MIN(ymost1, ymost2);
if (temp <= y) {
Empty();
return PR_FALSE;
Expand Down Expand Up @@ -134,12 +121,12 @@ PRBool nsRect::UnionRect(const nsRect &aRect1, const nsRect &aRect2)
nscoord ymost2 = aRect2.YMost();

// Compute the origin
x = MIN(aRect1.x, aRect2.x);
y = MIN(aRect1.y, aRect2.y);
x = PR_MIN(aRect1.x, aRect2.x);
y = PR_MIN(aRect1.y, aRect2.y);

// Compute the size
width = MAX(xmost1, xmost2) - x;
height = MAX(ymost1, ymost2) - y;
width = PR_MAX(xmost1, xmost2) - x;
height = PR_MAX(ymost1, ymost2) - y;
}

return result;
Expand Down Expand Up @@ -168,17 +155,17 @@ void nsRect::Deflate(nscoord aDx, nscoord aDy)
{
x += aDx;
y += aDy;
width -= 2 * aDx;
height -= 2 * aDy;
width = PR_MAX(0, width - 2 * aDx);
height = PR_MAX(0, height - 2 * aDy);
}

// Deflate the rect by the specified margin
void nsRect::Deflate(const nsMargin &aMargin)
{
x += aMargin.left;
y += aMargin.top;
width -= aMargin.left + aMargin.right;
height -= aMargin.top + aMargin.bottom;
width = PR_MAX(0, width - aMargin.LeftRight());
height = PR_MAX(0, height - aMargin.TopBottom());
}

// scale the rect but round to smallest containing rect
Expand Down Expand Up @@ -252,19 +239,19 @@ PRBool nsIntRect::IntersectRect(const nsIntRect &aRect1, const nsIntRect &aRect2
PRInt32 ymost2 = aRect2.YMost();
PRInt32 temp;

x = MAX(aRect1.x, aRect2.x);
y = MAX(aRect1.y, aRect2.y);
x = PR_MAX(aRect1.x, aRect2.x);
y = PR_MAX(aRect1.y, aRect2.y);

// Compute the destination width
temp = MIN(xmost1, xmost2);
temp = PR_MIN(xmost1, xmost2);
if (temp <= x) {
Empty();
return PR_FALSE;
}
width = temp - x;

// Compute the destination height
temp = MIN(ymost1, ymost2);
temp = PR_MIN(ymost1, ymost2);
if (temp <= y) {
Empty();
return PR_FALSE;
Expand Down Expand Up @@ -301,12 +288,12 @@ PRBool nsIntRect::UnionRect(const nsIntRect &aRect1, const nsIntRect &aRect2)
PRInt32 ymost2 = aRect2.YMost();

// Compute the origin
x = MIN(aRect1.x, aRect2.x);
y = MIN(aRect1.y, aRect2.y);
x = PR_MIN(aRect1.x, aRect2.x);
y = PR_MIN(aRect1.y, aRect2.y);

// Compute the size
width = MAX(xmost1, xmost2) - x;
height = MAX(ymost1, ymost2) - y;
width = PR_MAX(xmost1, xmost2) - x;
height = PR_MAX(ymost1, ymost2) - y;
}

return result;
Expand Down

0 comments on commit 10e5914

Please sign in to comment.