diff options
author | 2016-01-12 07:21:19 -0800 | |
---|---|---|
committer | 2016-01-12 07:21:19 -0800 | |
commit | c63a0f8fe534eef8d52abc2066126729be9b497c (patch) | |
tree | 2f9e298931408e516e2f421e7bc785304f555e25 /include/core/SkFixed.h | |
parent | 32cdc32522bf39a8236880f57ff4ee5b26bdd363 (diff) |
clamp fixed divide to 32 bits
In SkEdge::setLine, the numerator is a 26.6 fixed number.
SkFixedDiv shifts it up by an additional 16 bits. If the
y interval is small, the result overflows 32 bits.
The code pins in 64 bit space before down-casting the result.
R=reed@google.com
BUG=skia:4708
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1583453002
Review URL: https://codereview.chromium.org/1583453002
Diffstat (limited to 'include/core/SkFixed.h')
-rw-r--r-- | include/core/SkFixed.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h index 3140b7a35d..f6dd3d6002 100644 --- a/include/core/SkFixed.h +++ b/include/core/SkFixed.h @@ -86,9 +86,9 @@ typedef int32_t SkFixed; #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB) #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) #else - // TODO(reed): this clamp shouldn't be needed. Use SkToS32(). + // The divide may exceed 32 bits. Clamp to a signed 32 bit result. #define SkFixedDiv(numer, denom) \ - SkTPin<int32_t>((int32_t)(SkLeftShift((int64_t)numer, 16) / denom), SK_MinS32, SK_MaxS32) + SkToS32(SkTPin<int64_t>((SkLeftShift((int64_t)numer, 16) / denom), SK_MinS32, SK_MaxS32)) #endif ////////////////////////////////////////////////////////////////////////////////////////////////////// |