Proposed fix for crash in Cr70244.
authorwjmaclean@chromium.org <wjmaclean@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 7 Feb 2011 17:48:37 +0000 (17:48 +0000)
committerwjmaclean@chromium.org <wjmaclean@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 7 Feb 2011 17:48:37 +0000 (17:48 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@764 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkRect.h
src/core/SkCanvas.cpp
src/core/SkRect.cpp

index 00e0aaf..b6caad5 100644 (file)
@@ -296,6 +296,7 @@ struct SkRect {
     /** Return true if the rectangle's width or height are <= 0
     */
     bool        isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+    bool        hasValidCoordinates() const;
     SkScalar    width() const { return fRight - fLeft; }
     SkScalar    height() const { return fBottom - fTop; }
     SkScalar    centerX() const { return SkScalarHalf(fLeft + fRight); }
index faf030c..b05d424 100644 (file)
@@ -991,6 +991,10 @@ void SkCanvas::computeLocalClipBoundsCompareType(EdgeType et) const {
     antialiasing (worst case)
  */
 bool SkCanvas::quickReject(const SkRect& rect, EdgeType et) const {
+
+    if (!rect.hasValidCoordinates())
+        return true;
+
     if (fMCRec->fRegion->isEmpty()) {
         return true;
     }
index 7d73249..b9e6f19 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "SkRect.h"
+#include <limits>
 
 void SkIRect::join(int32_t left, int32_t top, int32_t right, int32_t bottom)
 {
@@ -44,6 +45,19 @@ void SkIRect::sort()
 
 /////////////////////////////////////////////////////////////////////////////
 
+template <typename NumType> static inline bool isValidRange(const NumType& x)
+{
+    static const NumType max = std::numeric_limits<NumType>::max();
+    return x >= -max && x <= max;
+}
+
+
+bool SkRect::hasValidCoordinates() const
+{
+    return isValidRange<SkScalar>(fLeft) && isValidRange<SkScalar>(fRight) &&
+           isValidRange<SkScalar>(fTop) && isValidRange<SkScalar>(fBottom);
+}
+
 void SkRect::sort()
 {
     if (fLeft > fRight)