aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-07-25 15:20:25 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-25 20:06:16 +0000
commite1789af3378c83f78695ca828ea6d0315860cc11 (patch)
tree241e5eff7ac8c545517d5e4ef913fe810c1b03cc
parent6668a514ac5d507359a885480cbaabd812ef92db (diff)
Don't double check in SkArenaAlloc.
Currently many range checks are being forced when they aren't needed. Change-Id: I5ad6933a15fa063e76045757c7523f17900e4c1a Reviewed-on: https://skia-review.googlesource.com/142816 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
-rw-r--r--include/private/SkArenaAlloc.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/include/private/SkArenaAlloc.h b/include/private/SkArenaAlloc.h
index 1915f8f9be..f39ebee208 100644
--- a/include/private/SkArenaAlloc.h
+++ b/include/private/SkArenaAlloc.h
@@ -8,6 +8,8 @@
#ifndef SkArenaAlloc_DEFINED
#define SkArenaAlloc_DEFINED
+#include "../private/SkTFitsIn.h"
+
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -98,6 +100,7 @@ public:
template <typename T>
T* makeArrayDefault(size_t count) {
+ AssertRelease(SkTFitsIn<uint32_t>(count));
uint32_t safeCount = ToU32(count);
T* array = (T*)this->commonArrayAlloc<T>(safeCount);
@@ -110,6 +113,7 @@ public:
template <typename T>
T* makeArray(size_t count) {
+ AssertRelease(SkTFitsIn<uint32_t>(count));
uint32_t safeCount = ToU32(count);
T* array = (T*)this->commonArrayAlloc<T>(safeCount);
@@ -123,6 +127,7 @@ public:
// Only use makeBytesAlignedTo if none of the typed variants are impractical to use.
void* makeBytesAlignedTo(size_t size, size_t align) {
+ AssertRelease(SkTFitsIn<uint32_t>(size));
auto objStart = this->allocObject(ToU32(size), ToU32(align));
fCursor = objStart + size;
return objStart;
@@ -134,9 +139,7 @@ public:
private:
static void AssertRelease(bool cond) { if (!cond) { ::abort(); } }
static uint32_t ToU32(size_t v) {
-#if SIZE_MAX > 0xffffffff
- AssertRelease(v <= 0xffffffff);
-#endif
+ assert(SkTFitsIn<uint32_t>(v));
return (uint32_t)v;
}