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

Unified Diff: src/core/SkEdge.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/SkEdge.cpp
diff --git a/src/core/SkEdge.cpp b/src/core/SkEdge.cpp
index f91f5f87829c45cd221dcefecfe00f6091f8f0e4..a1719f45709686604cbaf201811832fb8aded236 100644
--- a/src/core/SkEdge.cpp
+++ b/src/core/SkEdge.cpp
@@ -26,7 +26,7 @@
static inline SkFixed SkFDot6ToFixedDiv2(SkFDot6 value) {
// we want to return SkFDot6ToFixed(value >> 1), but we don't want to throw
// away data in value, so just perform a modify up-shift
- return value << (16 - 6 - 1);
+ return value * (1 << (16 - 6 - 1));
}
/////////////////////////////////////////////////////////////////////////
@@ -214,8 +214,8 @@ int SkQuadraticEdge::setQuadratic(const SkPoint pts[3], int shift)
// compute number of steps needed (1 << shift)
{
- SkFDot6 dx = ((x1 << 1) - x0 - x2) >> 2;
- SkFDot6 dy = ((y1 << 1) - y0 - y2) >> 2;
+ SkFDot6 dx = (x1 * 2 - x0 - x2) >> 2;
+ SkFDot6 dy = (y1 * 2 - y0 - y2) >> 2;
shift = diff_to_shift(dx, dy);
SkASSERT(shift >= 0);
}
@@ -312,8 +312,8 @@ int SkQuadraticEdge::updateQuadratic()
/////////////////////////////////////////////////////////////////////////
static inline int SkFDot6UpShift(SkFDot6 x, int upShift) {
- SkASSERT((x << upShift >> upShift) == x);
- return x << upShift;
+ SkASSERT((x * (1 << upShift) >> upShift) == x);
+ return x * (1 << upShift);
}
/* f(1/3) = (8a + 12b + 6c + d) / 27
@@ -403,7 +403,7 @@ int SkCubicEdge::setCubic(const SkPoint pts[4], int shift) {
}
fWinding = SkToS8(winding);
- fCurveCount = SkToS8(-1 << shift);
+ fCurveCount = SkToS8((signed) ((unsigned) -1 << shift));
fCurveShift = SkToU8(shift);
fCubicDShift = SkToU8(downShift);
« include/core/SkFixed.h ('K') | « src/core/SkEdge.h ('k') | src/core/SkFDot6.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698