| Index: include/core/SkFixed.h
|
| diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h
|
| index c2a0a7a4fbf56a30fa5d6026fdb490ab804b5cff..48284effda6110f0011248d73efd590f930de621 100644
|
| --- a/include/core/SkFixed.h
|
| +++ b/include/core/SkFixed.h
|
| @@ -60,11 +60,15 @@ typedef int32_t SkFixed;
|
| inline SkFixed SkIntToFixed(int n)
|
| {
|
| SkASSERT(n >= -32768 && n <= 32767);
|
| - return n << 16;
|
| + // Left shifting a negative value has undefined behavior in C, so we cast to unsigned before
|
| + // shifting.
|
| + return (unsigned)n << 16;
|
| }
|
| #else
|
| - // force the cast to SkFixed to ensure that the answer is signed (like the debug version)
|
| - #define SkIntToFixed(n) (SkFixed)((n) << 16)
|
| + // Left shifting a negative value has undefined behavior in C, so we cast to unsigned before
|
| + // shifting. Then we force the cast to SkFixed to ensure that the answer is signed (like the
|
| + // debug version).
|
| + #define SkIntToFixed(n) (SkFixed)((unsigned)(n) << 16)
|
| #endif
|
|
|
| #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16)
|
|
|