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

Unified Diff: src/core/SkFloatBits.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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkFloatBits.cpp
diff --git a/src/core/SkFloatBits.cpp b/src/core/SkFloatBits.cpp
index 919fd0610f2205e0706750395fbd2677abfb9db0..996a30bbca37db97a7f54f206520f9f8214a95ac 100644
--- a/src/core/SkFloatBits.cpp
+++ b/src/core/SkFloatBits.cpp
@@ -65,7 +65,7 @@ int32_t SkFloatBits_toIntCast(int32_t packed) {
// same as (int)floor(float)
int32_t SkFloatBits_toIntFloor(int32_t packed) {
// curse you negative 0
- if ((packed << 1) == 0) {
+ if (packed * 2 == 0) {
return 0;
}
@@ -104,7 +104,7 @@ int32_t SkFloatBits_toIntFloor(int32_t packed) {
// same as (int)floor(float + 0.5)
int32_t SkFloatBits_toIntRound(int32_t packed) {
// curse you negative 0
- if ((packed << 1) == 0) {
+ if (packed * 2 == 0) {
return 0;
}
@@ -134,7 +134,7 @@ int32_t SkFloatBits_toIntRound(int32_t packed) {
// same as (int)ceil(float)
int32_t SkFloatBits_toIntCeil(int32_t packed) {
// curse you negative 0
- if ((packed << 1) == 0) {
+ if (packed * 2 == 0) {
return 0;
}
@@ -200,6 +200,6 @@ float SkIntToFloatCast(int32_t value) {
SkASSERT(shift >= 0 && shift <= 255);
SkFloatIntUnion data;
- data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BIG);
+ data.fSignBitInt = sign * (1 << 31) | shift * (1 << 23) | (value & ~MATISSA_MAGIC_BIG);
return data.fFloat;
}
« include/core/SkFixed.h ('K') | « src/core/SkFDot6.h ('k') | src/core/SkMath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698