diff options
author | Chris Dalton <csmartdalton@google.com> | 2017-10-31 12:35:54 -0600 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-31 22:05:16 +0000 |
commit | 4dbdc677affd61309f1da173096089fdd20219b3 (patch) | |
tree | 77c2d5e9bc254a8dae955bf4eb6829afe17bd809 /src/core/SkGeometry.cpp | |
parent | 6982400f9a414bbe7cff5e2dd32cf9893b07c370 (diff) |
Fix undefined behavior in normalize_t_s
BUG=chromium:743617
Change-Id: I00ad3103cdd5b7d2eac3b6827a3c2932009042a9
Reviewed-on: https://skia-review.googlesource.com/65860
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/core/SkGeometry.cpp')
-rw-r--r-- | src/core/SkGeometry.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp index 6a5207b9ed..83208aa717 100644 --- a/src/core/SkGeometry.cpp +++ b/src/core/SkGeometry.cpp @@ -565,16 +565,23 @@ static void normalize_t_s(double t[], double s[], int count) { // Keep the exponents at or below zero to avoid overflow down the road. for (int i = 0; i < count; ++i) { SkASSERT(0 != s[i]); - union { double value; int64_t bits; } tt, ss, norm; - tt.value = t[i]; - ss.value = s[i]; - int64_t expT = ((tt.bits >> 52) & 0x7ff) - 1023, - expS = ((ss.bits >> 52) & 0x7ff) - 1023; + + int64_t expT; + memcpy(&expT, &t[i], sizeof(double)); + expT = ((expT >> 52) & 0x7ff) - 1023; + + int64_t expS; + memcpy(&expS, &s[i], sizeof(double)); + expS = ((expS >> 52) & 0x7ff) - 1023; + + double norm; int64_t expNorm = -SkTMax(expT, expS) + 1023; SkASSERT(expNorm > 0 && expNorm < 2047); // ensure we have a valid non-zero exponent. - norm.bits = expNorm << 52; - t[i] *= norm.value; - s[i] *= norm.value; + expNorm = expNorm << 52; + memcpy(&norm, &expNorm, sizeof(double)); + + t[i] *= norm; + s[i] *= norm; } } |