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

Unified Diff: src/core/SkXfermode.cpp

Issue 114173002: Preventing division by 0 (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkXfermode.cpp
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 8cb79c2dbd29f3682450f4392bb5ff04347ca9cf..176bcb50ea74147d6e2da105103a1682980f2929 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -468,16 +468,18 @@ static inline void clipColor(int* r, int* g, int* b, int a) {
int L = Lum(*r, *g, *b);
int n = minimum(*r, *g, *b);
int x = maximum(*r, *g, *b);
- if(n < 0) {
- *r = L + SkMulDiv(*r - L, L, L - n);
- *g = L + SkMulDiv(*g - L, L, L - n);
- *b = L + SkMulDiv(*b - L, L, L - n);
+ int denom;
+ if ((n < 0) && (denom = L - n)) { // Compute denom and make sure it's non zero
+ *r = L + SkMulDiv(*r - L, L, denom);
+ *g = L + SkMulDiv(*g - L, L, denom);
+ *b = L + SkMulDiv(*b - L, L, denom);
}
- if (x > a) {
- *r = L + SkMulDiv(*r - L, a - L, x - L);
- *g = L + SkMulDiv(*g - L, a - L, x - L);
- *b = L + SkMulDiv(*b - L, a - L, x - L);
+ if ((x > a) && (denom = x - L)) { // Compute denom and make sure it's non zero
+ int numer = a - L;
+ *r = L + SkMulDiv(*r - L, numer, denom);
+ *g = L + SkMulDiv(*g - L, numer, denom);
+ *b = L + SkMulDiv(*b - L, numer, denom);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698