diff options
author | Mike Reed <reed@google.com> | 2018-05-24 10:39:57 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-24 15:16:43 +0000 |
commit | d2e74b8080e9ea3b0aac371d4c75190d55b151eb (patch) | |
tree | 9c7cdaf673b8af704a33101582167a88f522d671 /include/core/SkRect.h | |
parent | 75bf216c033896ffeff5176e8b5f5fb79c02f8fb (diff) |
compute center slightly slower to avoid overflow
Bug: oss-fuzz:8509
Change-Id: I13b1a77e1549070827a7cc534b062ec85aad255e
Reviewed-on: https://skia-review.googlesource.com/129930
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'include/core/SkRect.h')
-rw-r--r-- | include/core/SkRect.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h index 2a46da68c6..920572f317 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -931,14 +931,20 @@ struct SK_API SkRect { @return midpoint in x */ - SkScalar centerX() const { return SkScalarHalf(fLeft + fRight); } + SkScalar centerX() const { + // don't use SkScalarHalf(fLeft + fBottom) as that might overflow before the 0.5 + return SkScalarHalf(fLeft) + SkScalarHalf(fRight); + } /** Returns average of top edge and bottom edge. Result does not change if SkRect is sorted. Result may overflow to infinity if SkRect is far from the origin. @return midpoint in y */ - SkScalar centerY() const { return SkScalarHalf(fTop + fBottom); } + SkScalar centerY() const { + // don't use SkScalarHalf(fTop + fBottom) as that might overflow before the 0.5 + return SkScalarHalf(fTop) + SkScalarHalf(fBottom); + } /** Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are equal to the corresponding members in b. |