aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar tomhudson <tomhudson@google.com>2015-12-07 10:38:05 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-12-07 10:38:05 -0800
commitd5c4265b49d212f7888d0516328f39c4d45d3058 (patch)
treefa6394fa20aa2c2bf26f1aa9efa88d0ff2da5122
parentd18b1b5adc15afd9b57ddecf779dccbcc85098f1 (diff)
Fix up signed-integer-overflow warnings
When checking whether a matrix was a pure scale, we subtracted 0x3f800000 from the diagonals; if the diagonal value was already very negative, we'd underflow. Replace subtraction with XOR. When dealing with repeating tiled bitmaps, when the bitmap was very large, we'd multiply an offset by 65535, possibly causing underflow. Throw in a cast to long (casting to unsigned also silences the warning and wouldn't involve extension, but I can't convince myself that it's correct). BUG=skia:4635 R=mtklein@google.com Review URL: https://codereview.chromium.org/1504933002
-rw-r--r--src/core/SkBitmapProcState_matrixProcs.cpp14
-rw-r--r--src/core/SkMatrix.cpp2
2 files changed, 9 insertions, 7 deletions
diff --git a/src/core/SkBitmapProcState_matrixProcs.cpp b/src/core/SkBitmapProcState_matrixProcs.cpp
index 1870a0e50e..ee61ee8556 100644
--- a/src/core/SkBitmapProcState_matrixProcs.cpp
+++ b/src/core/SkBitmapProcState_matrixProcs.cpp
@@ -95,18 +95,20 @@ static SkBitmapProcState::MatrixProc ClampX_ClampY_Procs[] = {
};
#define MAKENAME(suffix) RepeatX_RepeatY ## suffix
-#define TILEX_PROCF(fx, max) SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1))
-#define TILEY_PROCF(fy, max) SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1))
-#define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
-#define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
+#define TILEX_PROCF(fx, max) SK_USHIFT16((unsigned)((fx) & 0xFFFF) * ((max) + 1))
+#define TILEY_PROCF(fy, max) SK_USHIFT16((unsigned)((fy) & 0xFFFF) * ((max) + 1))
+#define TILEX_LOW_BITS(fx, max) (((unsigned)((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
+#define TILEY_LOW_BITS(fy, max) (((unsigned)((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
#include "SkBitmapProcState_matrix.h"
struct RepeatTileProcs {
static unsigned X(const SkBitmapProcState&, SkFixed fx, int max) {
- return SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1));
+ SkASSERT(max < 65535);
+ return SK_USHIFT16((unsigned)((fx) & 0xFFFF) * ((max) + 1));
}
static unsigned Y(const SkBitmapProcState&, SkFixed fy, int max) {
- return SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1));
+ SkASSERT(max < 65535);
+ return SK_USHIFT16((unsigned)((fy) & 0xFFFF) * ((max) + 1));
}
};
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index b32f372bbd..6101eb9f9a 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -156,7 +156,7 @@ uint8_t SkMatrix::computeTypeMask() const {
} else {
// Only test for scale explicitly if not affine, since affine sets the
// scale bit.
- if ((m00 - kScalar1Int) | (m11 - kScalar1Int)) {
+ if ((m00 ^ kScalar1Int) | (m11 ^ kScalar1Int)) {
mask |= kScale_Mask;
}