diff options
author | Mike Reed <reed@google.com> | 2018-01-05 11:20:10 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-05 21:29:35 +0000 |
commit | 8dc8dbc8211e7b0245a6e7db911265efbe0fccaf (patch) | |
tree | f112c74f618a536e86a80d9d657b804a039f3f54 /include/private/SkTemplates.h | |
parent | f21b32ccd7bd174ce647078854b2314f8b64d94c (diff) |
begin cleanup of malloc porting layer
1. Merge some of the allocators into sk_malloc_flags by redefining a flag to mean zero-init
2. Add more private helpers to simplify our call-sites (and handle some overflow mul checks)
3. The 2-param helpers rely on the saturating SkSafeMath::Mul to pass max_size_t as the request,
which should always fail.
Bug:508641
Change-Id: I322f1e6ed91113467e0fdb12c91c3dad33d890c8
Reviewed-on: https://skia-review.googlesource.com/90940
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Stephan Altmueller <stephana@google.com>
Diffstat (limited to 'include/private/SkTemplates.h')
-rw-r--r-- | include/private/SkTemplates.h | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h index 8a605fbd02..3f70203555 100644 --- a/include/private/SkTemplates.h +++ b/include/private/SkTemplates.h @@ -175,12 +175,7 @@ public: } if (count > kCount) { - const uint64_t size64 = sk_64_mul(count, sizeof(T)); - const size_t size = static_cast<size_t>(size64); - if (size != size64) { - sk_out_of_memory(); - } - fArray = (T*) sk_malloc_throw(size); + fArray = (T*) sk_malloc_throw(count, sizeof(T)); } else if (count > 0) { fArray = (T*) fStorage; } else { @@ -250,7 +245,7 @@ public: /** Allocates space for 'count' Ts. */ explicit SkAutoTMalloc(size_t count) { - fPtr = count ? (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW) : nullptr; + fPtr = count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr; } SkAutoTMalloc(SkAutoTMalloc<T>&& that) : fPtr(that.release()) {} @@ -271,7 +266,7 @@ public: /** Resize the memory area pointed to by the current ptr without preserving contents. */ T* reset(size_t count = 0) { sk_free(fPtr); - fPtr = count ? (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW) : nullptr; + fPtr = count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr; return fPtr; } @@ -322,7 +317,7 @@ public: SkAutoSTMalloc(size_t count) { if (count > kCount) { - fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP); + fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { fPtr = fTStorage; } else { @@ -342,7 +337,7 @@ public: sk_free(fPtr); } if (count > kCount) { - fPtr = (T*)sk_malloc_throw(count * sizeof(T)); + fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { fPtr = fTStorage; } else { @@ -373,14 +368,14 @@ public: void realloc(size_t count) { if (count > kCount) { if (fPtr == fTStorage) { - fPtr = (T*)sk_malloc_throw(count * sizeof(T)); + fPtr = (T*)sk_malloc_throw(count, sizeof(T)); memcpy(fPtr, fTStorage, kCount * sizeof(T)); } else { - fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T)); + fPtr = (T*)sk_realloc_throw(fPtr, count, sizeof(T)); } } else if (count) { if (fPtr != fTStorage) { - fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T)); + fPtr = (T*)sk_realloc_throw(fPtr, count, sizeof(T)); } } else { this->reset(0); |