Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: src/core/SkMath.cpp

Issue 1503423003: ubsan shift fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMathPriv.h" 8 #include "SkMathPriv.h"
9 #include "SkFloatBits.h" 9 #include "SkFloatBits.h"
10 #include "SkFloatingPoint.h" 10 #include "SkFloatingPoint.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 int dbits = SkCLZ(denom) - 1; 65 int dbits = SkCLZ(denom) - 1;
66 int bits = shift_bias - nbits + dbits; 66 int bits = shift_bias - nbits + dbits;
67 67
68 if (bits < 0) { // answer will underflow 68 if (bits < 0) { // answer will underflow
69 return 0; 69 return 0;
70 } 70 }
71 if (bits > 31) { // answer will overflow 71 if (bits > 31) { // answer will overflow
72 return SkApplySign(SK_MaxS32, sign); 72 return SkApplySign(SK_MaxS32, sign);
73 } 73 }
74 74
75 denom <<= dbits; 75 denom *= 1 << dbits;
76 numer <<= nbits; 76 numer *= 1 << nbits;
77 77
78 SkFixed result = 0; 78 SkFixed result = 0;
79 79
80 // do the first one 80 // do the first one
81 if ((numer -= denom) >= 0) { 81 if ((numer -= denom) >= 0) {
82 result = 1; 82 result = 1;
83 } else { 83 } else {
84 numer += denom; 84 numer += denom;
85 } 85 }
86 86
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (SkScalarNearlyZero(*cosValue)) { 146 if (SkScalarNearlyZero(*cosValue)) {
147 *cosValue = 0; 147 *cosValue = 0;
148 } 148 }
149 } 149 }
150 150
151 if (SkScalarNearlyZero(sinValue)) { 151 if (SkScalarNearlyZero(sinValue)) {
152 sinValue = 0; 152 sinValue = 0;
153 } 153 }
154 return sinValue; 154 return sinValue;
155 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698