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

Unified Diff: ui/gfx/geometry/point.h

Issue 2354783004: Fix overflow/underflow in gfx geometry once and for all (Closed)
Patch Set: Remove accessibility test changes Created 4 years, 2 months 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/geometry/mojo/geometry.typemap ('k') | ui/gfx/geometry/point_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/point.h
diff --git a/ui/gfx/geometry/point.h b/ui/gfx/geometry/point.h
index 6de899c3d3c4d64d76304b8f9708a2a92cb4d5f6..f1d1e3af76492b8d12e4f23eb192a1de6164002c 100644
--- a/ui/gfx/geometry/point.h
+++ b/ui/gfx/geometry/point.h
@@ -10,6 +10,7 @@
#include <tuple>
#include "build/build_config.h"
+#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/gfx_export.h"
@@ -55,18 +56,18 @@ class GFX_EXPORT Point {
}
void Offset(int delta_x, int delta_y) {
- x_ += delta_x;
- y_ += delta_y;
+ x_ = SafeAdd(x_, delta_x);
+ y_ = SafeAdd(y_, delta_y);
}
void operator+=(const Vector2d& vector) {
- x_ += vector.x();
- y_ += vector.y();
+ x_ = SafeAdd(x_, vector.x());
+ y_ = SafeAdd(y_, vector.y());
}
void operator-=(const Vector2d& vector) {
- x_ -= vector.x();
- y_ -= vector.y();
+ x_ = SafeSubtract(x_, vector.x());
+ y_ = SafeSubtract(y_, vector.y());
}
void SetToMin(const Point& other);
@@ -115,7 +116,8 @@ inline Point operator-(const Point& lhs, const Vector2d& rhs) {
}
inline Vector2d operator-(const Point& lhs, const Point& rhs) {
- return Vector2d(lhs.x() - rhs.x(), lhs.y() - rhs.y());
+ return Vector2d(SafeSubtract(lhs.x(), rhs.x()),
+ SafeSubtract(lhs.y(), rhs.y()));
}
inline Point PointAtOffsetFromOrigin(const Vector2d& offset_from_origin) {
« no previous file with comments | « ui/gfx/geometry/mojo/geometry.typemap ('k') | ui/gfx/geometry/point_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698