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

Unified Diff: ui/gfx/transform.cc

Issue 2585263003: Avoid overflow when checking if a transform is integer translation. (Closed)
Patch Set: integer-transform Created 4 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 | « ui/gfx/transform.h ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/transform.cc
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index 6a44391c02760477e2eeddb75b4da9e3c59980d1..9c8a005389ff5dfc7f1e4545ed021a71b499c715 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -246,10 +246,13 @@ bool Transform::IsIdentityOrIntegerTranslation() const {
if (!IsIdentityOrTranslation())
return false;
+ float t[] = {matrix_.get(0, 3), matrix_.get(1, 3), matrix_.get(2, 3)};
bool no_fractional_translation =
- static_cast<int>(matrix_.get(0, 3)) == matrix_.get(0, 3) &&
- static_cast<int>(matrix_.get(1, 3)) == matrix_.get(1, 3) &&
- static_cast<int>(matrix_.get(2, 3)) == matrix_.get(2, 3);
+ base::IsValueInRangeForNumericType<int>(t[0]) &&
+ base::IsValueInRangeForNumericType<int>(t[1]) &&
+ base::IsValueInRangeForNumericType<int>(t[2]) &&
+ static_cast<int>(t[0]) == t[0] && static_cast<int>(t[1]) == t[1] &&
+ static_cast<int>(t[2]) == t[2];
return no_fractional_translation;
}
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698