Index: skia/sgl/SkMask.cpp |
=================================================================== |
--- skia/sgl/SkMask.cpp (revision 14480) |
+++ skia/sgl/SkMask.cpp (working copy) |
@@ -15,41 +15,29 @@ |
** limitations under the License. |
*/ |
-#include <limits> |
- |
+#include "Sk64.h" |
#include "SkMask.h" |
-size_t SkMask::computeImageSize() const |
-{ |
- // Prevent too large a number. There is a better fix for this in Skia |
- // trunk where it returns failure. |
- long long size = (long long)fBounds.height() * (long long)fRowBytes; |
- if (size >= std::numeric_limits<size_t>::max() / 2) { |
-#ifdef WIN32 |
- __debugbreak(); |
-#else |
- abort(); |
-#endif |
+/** returns the product if it is positive and fits in 31 bits. Otherwise this |
+ returns 0. |
+ */ |
+static int32_t safeMul32(int32_t a, int32_t b) { |
+ Sk64 size; |
+ size.setMul(a, b); |
+ if (size.is32() && size.isPos()) { |
+ return size.get32(); |
} |
+ return 0; |
+} |
- return size; |
+size_t SkMask::computeImageSize() const { |
+ return safeMul32(fBounds.height(), fRowBytes); |
} |
-size_t SkMask::computeTotalImageSize() const |
-{ |
+size_t SkMask::computeTotalImageSize() const { |
size_t size = this->computeImageSize(); |
- |
if (fFormat == SkMask::k3D_Format) { |
- // See computeImageSize for why we want to stop here. |
- if (size > std::numeric_limits<size_t>::max() / 3) { |
-#ifdef WIN32 |
- __debugbreak(); |
-#else |
- abort(); |
-#endif |
- } |
- |
- size *= 3; |
+ size = safeMul32(size, 3); |
} |
return size; |
} |