add helper to check for overflow

pre-CL to aid in changing the convention for when we overflow

Bug: skia:
Change-Id: I1e34a18fefb80187787a1c0c8ed7ee3516744d24
Reviewed-on: https://skia-review.googlesource.com/57103
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-10-09 10:42:51 -04:00 committed by Skia Commit-Bot
parent c6b2e6b061
commit c5eb97dd88
6 changed files with 11 additions and 6 deletions

View File

@ -332,6 +332,11 @@ public:
return this->computeByteSize(this->minRowBytes());
}
// Returns true if the result of computeByteSize (or computeMinByteSize) overflowed
static bool ByteSizeOverflowed(size_t byteSize) {
return 0 == byteSize;
}
bool validRowBytes(size_t rowBytes) const {
uint64_t minRB = sk_64_mul(fWidth, this->bytesPerPixel());
return rowBytes >= minRB;

View File

@ -37,7 +37,7 @@ bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
size_t rb;
size_t size = AllocSize(info, &rb);
if (0 == size) {
if (SkImageInfo::ByteSizeOverflowed(size)) {
return false;
}
void* pixels = sk_malloc_flags(size, 0);

View File

@ -290,7 +290,7 @@ SkBitmapCache::RecPtr SkBitmapCache::Alloc(const SkBitmapCacheDesc& desc, const
const size_t rb = info.minRowBytes();
size_t size = info.computeByteSize(rb);
if (0 == size) {
if (SkImageInfo::ByteSizeOverflowed(size)) {
return nullptr;
}

View File

@ -80,8 +80,8 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*allocProc)(size_t),
size_t size = 0;
if (!info.isEmpty() && rowBytes) {
size = info.computeByteSize(rowBytes);
if (!size) {
return nullptr; // overflow
if (SkImageInfo::ByteSizeOverflowed(size)) {
return nullptr;
}
}
#endif

View File

@ -423,7 +423,7 @@ sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src,
size_t rowBytes = info.minRowBytes();
size_t size = info.computeByteSize(rowBytes);
if (size == 0) {
if (SkImageInfo::ByteSizeOverflowed(size)) {
return nullptr;
}
auto data = SkData::MakeUninitialized(size);

View File

@ -62,7 +62,7 @@ public:
}
size_t size = info.computeByteSize(rowBytes);
if (0 == size) {
if (SkImageInfo::ByteSizeOverflowed(size)) {
return false;
}