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

Unified Diff: ui/gfx/skia_util.cc

Issue 2231243002: Use CheckedNumeric when converting SkIRect to gfx::Rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 4 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/skia_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/skia_util.cc
diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc
index ca991c79ec542a7a56c2c8de334610f257cb0563..b824c106eb5cb69da44c7671d407ed0239bc6a1b 100644
--- a/ui/gfx/skia_util.cc
+++ b/ui/gfx/skia_util.cc
@@ -8,6 +8,7 @@
#include <stdint.h>
#include "base/numerics/safe_conversions.h"
+#include "base/numerics/safe_math.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkColorPriv.h"
@@ -46,10 +47,27 @@ SkIRect RectToSkIRect(const Rect& rect) {
return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height());
}
+SkIRect RectToSkIRectChecked(const Rect& rect) {
+ return SkIRect::MakeLTRB(
+ rect.x(), rect.y(),
+ (base::CheckedNumeric<int32_t>(rect.x()) + rect.width())
+ .ValueOrDefault(std::numeric_limits<int32_t>::max()),
+ (base::CheckedNumeric<int32_t>(rect.y()) + rect.height())
+ .ValueOrDefault(std::numeric_limits<int32_t>::max()));
+}
+
Rect SkIRectToRect(const SkIRect& rect) {
return Rect(rect.x(), rect.y(), rect.width(), rect.height());
}
+Rect SkIRectToRectChecked(const SkIRect& rect) {
danakj 2016/08/11 18:13:37 OK I think I'd rather not have Checked version tha
+ return Rect(rect.x(), rect.y(),
+ (base::CheckedNumeric<int>(rect.right()) - rect.left())
+ .ValueOrDefault(std::numeric_limits<int>::max()),
+ (base::CheckedNumeric<int>(rect.bottom()) - rect.top())
+ .ValueOrDefault(std::numeric_limits<int>::max()));
+}
+
SkRect RectFToSkRect(const RectF& rect) {
return SkRect::MakeXYWH(SkFloatToScalar(rect.x()),
SkFloatToScalar(rect.y()),
« no previous file with comments | « ui/gfx/skia_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698