fix undefined signed shifts
authorcaryclark <caryclark@google.com>
Fri, 26 Feb 2016 13:01:42 +0000 (05:01 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 26 Feb 2016 13:01:42 +0000 (05:01 -0800)
The expression (1 << 31) is technically undefined.

Fixed the undefined shift referenced by this bug and
a few friends.

R=reed@google.com
BUG=skia:2285
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1737363002

Review URL: https://codereview.chromium.org/1737363002

include/core/SkCanvas.h
include/core/SkTypes.h
include/private/SkFloatBits.h
src/gpu/effects/GrMatrixConvolutionEffect.cpp

index 0df5d0b..c23d748 100644 (file)
@@ -54,7 +54,7 @@ class SkTextBlob;
 */
 class SK_API SkCanvas : public SkRefCnt {
     enum PrivateSaveLayerFlags {
-        kDontClipToLayer_PrivateSaveLayerFlag   = 1 << 31,
+        kDontClipToLayer_PrivateSaveLayerFlag   = 1U << 31,
     };
     
 public:
index 756eae8..5831ba3 100644 (file)
@@ -290,7 +290,7 @@ typedef uint8_t SkBool8;
 #define SK_MinS32   -SK_MaxS32
 #define SK_MaxU32   0xFFFFFFFF
 #define SK_MinU32   0
-#define SK_NaN32    (1 << 31)
+#define SK_NaN32    ((int) (1U << 31))
 
 /** Returns true if the value can be represented with signed 16bits
  */
index 3ddb9ef..caad342 100644 (file)
@@ -32,7 +32,7 @@ static inline int32_t Sk2sComplimentToSignBit(int32_t x) {
     // make x positive
     x = (x ^ sign) - sign;
     // set the sign bit as needed
-    x |= sign << 31;
+    x |= SkLeftShift(sign, 31);
     return x;
 }
 
index ae8b9bf..e25cd22 100644 (file)
@@ -114,7 +114,7 @@ void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor,
     const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffect>();
     SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFFFF);
     uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height();
-    key |= m.convolveAlpha() ? 1 << 31 : 0;
+    key |= m.convolveAlpha() ? 1U << 31 : 0;
     b->add32(key);
     b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain()));
 }