diff options
-rw-r--r-- | include/private/SkArenaAlloc.h | 9 |
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; } |