diff options
-rw-r--r-- | include/core/SkEndian.h | 13 | ||||
-rw-r--r-- | include/core/SkReadBuffer.h | 4 | ||||
-rw-r--r-- | include/core/SkReader32.h | 8 | ||||
-rw-r--r-- | src/core/SkReadBuffer.cpp | 4 | ||||
-rw-r--r-- | src/core/SkRegion.cpp | 4 | ||||
-rw-r--r-- | src/core/SkRegionPriv.h | 4 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 5 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 16 | ||||
-rw-r--r-- | src/core/SkValidatingReadBuffer.cpp | 4 | ||||
-rw-r--r-- | src/core/SkWriter32.cpp | 2 | ||||
-rw-r--r-- | src/sfnt/SkOTUtils.cpp | 6 |
11 files changed, 34 insertions, 36 deletions
diff --git a/include/core/SkEndian.h b/include/core/SkEndian.h index 6eba297548..0955fcc505 100644 --- a/include/core/SkEndian.h +++ b/include/core/SkEndian.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkEndian_DEFINED #define SkEndian_DEFINED @@ -29,10 +27,10 @@ /** Swap the two bytes in the low 16bits of the parameters. e.g. 0x1234 -> 0x3412 */ -static inline uint16_t SkEndianSwap16(U16CPU value) { - SkASSERT(value == (uint16_t)value); +static inline uint16_t SkEndianSwap16(uint16_t value) { return static_cast<uint16_t>((value >> 8) | (value << 8)); } + template<uint16_t N> struct SkTEndianSwap16 { static const uint16_t value = static_cast<uint16_t>((N >> 8) | ((N & 0xFF) << 8)); }; @@ -53,11 +51,12 @@ static inline void SkEndianSwap16s(uint16_t array[], int count) { e.g. 0x12345678 -> 0x78563412 */ static inline uint32_t SkEndianSwap32(uint32_t value) { - return ((value & 0xFF) << 24) | - ((value & 0xFF00) << 8) | - ((value & 0xFF0000) >> 8) | + return ((value & 0xFF) << 24) | + ((value & 0xFF00) << 8) | + ((value & 0xFF0000) >> 8) | (value >> 24); } + template<uint32_t N> struct SkTEndianSwap32 { static const uint32_t value = ((N & 0xFF) << 24) | ((N & 0xFF00) << 8) | diff --git a/include/core/SkReadBuffer.h b/include/core/SkReadBuffer.h index f6b1919133..dfd92eedc0 100644 --- a/include/core/SkReadBuffer.h +++ b/include/core/SkReadBuffer.h @@ -69,8 +69,8 @@ public: SkReader32* getReader32() { return &fReader; } - uint32_t size() { return fReader.size(); } - uint32_t offset() { return fReader.offset(); } + size_t size() { return fReader.size(); } + size_t offset() { return fReader.offset(); } bool eof() { return fReader.eof(); } const void* skip(size_t size) { return fReader.skip(size); } void* readFunctionPtr() { return fReader.readPtr(); } diff --git a/include/core/SkReader32.h b/include/core/SkReader32.h index 40ae12ce23..7e8038d0ae 100644 --- a/include/core/SkReader32.h +++ b/include/core/SkReader32.h @@ -33,14 +33,14 @@ public: fStop = (const char*)data + size; } - uint32_t size() const { return SkToU32(fStop - fBase); } - uint32_t offset() const { return SkToU32(fCurr - fBase); } + size_t size() const { return fStop - fBase; } + size_t offset() const { return fCurr - fBase; } bool eof() const { return fCurr >= fStop; } const void* base() const { return fBase; } const void* peek() const { return fCurr; } - uint32_t available() const { return SkToU32(fStop - fCurr); } - bool isAvailable(uint32_t size) const { return fCurr + size <= fStop; } + size_t available() const { return fStop - fCurr; } + bool isAvailable(size_t size) const { return fCurr + size <= fStop; } void rewind() { fCurr = fBase; } diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index b60dee3ba6..b4bc87529a 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -321,10 +321,10 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) { SkFlattenable* obj = NULL; uint32_t sizeRecorded = fReader.readU32(); if (factory) { - uint32_t offset = fReader.offset(); + size_t offset = fReader.offset(); obj = (*factory)(*this); // check that we read the amount we expected - uint32_t sizeRead = fReader.offset() - offset; + size_t sizeRead = fReader.offset() - offset; if (sizeRecorded != sizeRead) { // we could try to fix up the offset... sk_throw(); diff --git a/src/core/SkRegion.cpp b/src/core/SkRegion.cpp index baedf2aea8..98670b6b52 100644 --- a/src/core/SkRegion.cpp +++ b/src/core/SkRegion.cpp @@ -796,7 +796,7 @@ public: fTop = (SkRegion::RunType)(bottom); // just update our bottom } else { start[-2] = (SkRegion::RunType)(bottom); - start[-1] = len >> 1; + start[-1] = SkToS32(len >> 1); fPrevDst = start; fPrevLen = len; } @@ -1212,7 +1212,7 @@ static void compute_bounds(const SkRegion::RunType runs[], const SkRegion::RunType* prev = runs; runs = skip_intervals_slow(runs); - int intervals = (runs - prev) >> 1; + int intervals = SkToInt((runs - prev) >> 1); SkASSERT(prev[-1] == intervals); intervalCount += intervals; diff --git a/src/core/SkRegionPriv.h b/src/core/SkRegionPriv.h index f299f3a9d6..c8f000df35 100644 --- a/src/core/SkRegionPriv.h +++ b/src/core/SkRegionPriv.h @@ -29,7 +29,7 @@ static int compute_intervalcount(const SkRegion::RunType runs[]) { SkASSERT(curr[1] < SkRegion::kRunTypeSentinel); curr += 2; } - return (curr - runs) >> 1; + return SkToInt((curr - runs) >> 1); } #endif @@ -213,7 +213,7 @@ public: #ifdef SK_DEBUG // +1 to skip the last Y-sentinel - int runCount = runs - this->writable_runs() + 1; + int runCount = SkToInt(runs - this->writable_runs() + 1); SkASSERT(runCount == fRunCount); #endif diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index d0d24eebe8..fee1ff7908 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -548,8 +548,9 @@ static void packA8ToA1(const SkMask& mask, const uint8_t* src, size_t srcRB) { const int dstPad = mask.fRowBytes - SkAlign8(width)/8; SkASSERT(dstPad >= 0); - const int srcPad = srcRB - width; - SkASSERT(srcPad >= 0); + SkASSERT(width >= 0); + SkASSERT(srcRB >= (size_t)width); + const size_t srcPad = srcRB - width; for (int y = 0; y < height; ++y) { for (int i = 0; i < octs; ++i) { diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index c60f2a738e..ebaac9ab15 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -161,7 +161,7 @@ bool SkWStream::writePackedUInt(size_t value) { memcpy(&data[1], &value16, 2); len = 3; } else { - uint32_t value32 = value; + uint32_t value32 = SkToU32(value); data[0] = SK_BYTE_SENTINEL_FOR_U32; memcpy(&data[1], &value32, 4); len = 5; @@ -189,7 +189,7 @@ bool SkWStream::writeStream(SkStream* stream, size_t length) { bool SkWStream::writeData(const SkData* data) { if (data) { - this->write32(data->size()); + this->write32(SkToU32(data->size())); this->write(data->data(), data->size()); } else { this->write32(0); @@ -481,11 +481,9 @@ SkMemoryWStream::SkMemoryWStream(void* buffer, size_t size) { } -bool SkMemoryWStream::write(const void* buffer, size_t size) -{ - size = SkMin32(size, fMaxLength - fBytesWritten); - if (size > 0) - { +bool SkMemoryWStream::write(const void* buffer, size_t size) { + size = SkTMin(size, fMaxLength - fBytesWritten); + if (size > 0) { memcpy(fBuffer + fBytesWritten, buffer, size); fBytesWritten += size; return true; @@ -558,7 +556,7 @@ bool SkDynamicMemoryWStream::write(const void* buffer, size_t count) size_t size; if (fTail != NULL && fTail->avail() > 0) { - size = SkMin32(fTail->avail(), count); + size = SkTMin(fTail->avail(), count); buffer = fTail->append(buffer, size); SkASSERT(count >= size); count -= size; @@ -566,7 +564,7 @@ bool SkDynamicMemoryWStream::write(const void* buffer, size_t count) return true; } - size = SkMax32(count, SkDynamicMemoryWStream_MinBlockSize); + size = SkTMax<size_t>(count, SkDynamicMemoryWStream_MinBlockSize); Block* block = (Block*)sk_malloc_throw(sizeof(Block) + size); block->init(size); block->append(buffer, count); diff --git a/src/core/SkValidatingReadBuffer.cpp b/src/core/SkValidatingReadBuffer.cpp index 8db2c68b9a..95bf83c847 100644 --- a/src/core/SkValidatingReadBuffer.cpp +++ b/src/core/SkValidatingReadBuffer.cpp @@ -256,10 +256,10 @@ SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type) SkFlattenable* obj = NULL; uint32_t sizeRecorded = this->readUInt(); if (factory) { - uint32_t offset = fReader.offset(); + size_t offset = fReader.offset(); obj = (*factory)(*this); // check that we read the amount we expected - uint32_t sizeRead = fReader.offset() - offset; + size_t sizeRead = fReader.offset() - offset; this->validate(sizeRecorded == sizeRead); if (fError) { // we could try to fix up the offset... diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp index c7bfd92d56..3397c37360 100644 --- a/src/core/SkWriter32.cpp +++ b/src/core/SkWriter32.cpp @@ -47,7 +47,7 @@ void SkWriter32::writeString(const char str[], size_t len) { // [ 4 byte len ] [ str ... ] [1 - 4 \0s] uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1); - *ptr = len; + *ptr = SkToU32(len); char* chars = (char*)(ptr + 1); memcpy(chars, str, len); chars[len] = '\0'; diff --git a/src/sfnt/SkOTUtils.cpp b/src/sfnt/SkOTUtils.cpp index 004a888310..e76d1da08c 100644 --- a/src/sfnt/SkOTUtils.cpp +++ b/src/sfnt/SkOTUtils.cpp @@ -103,7 +103,7 @@ SkData* SkOTUtils::RenameFont(SkStream* fontData, const char* fontName, int font for (; currentEntry < endEntry; ++currentEntry) { uint32_t oldOffset = SkEndian_SwapBE32(currentEntry->offset); if (oldOffset > oldNameTableOffset) { - currentEntry->offset = SkEndian_SwapBE32(oldOffset - oldNameTablePhysicalSize); + currentEntry->offset = SkEndian_SwapBE32(SkToU32(oldOffset - oldNameTablePhysicalSize)); } if (SkOTTableHead::TAG == currentEntry->tag) { headTableEntry = currentEntry; @@ -112,8 +112,8 @@ SkData* SkOTUtils::RenameFont(SkStream* fontData, const char* fontName, int font // Make the table directory entry point to the new 'name' table. SkSFNTHeader::TableDirectoryEntry* nameTableEntry = reinterpret_cast<SkSFNTHeader::TableDirectoryEntry*>(data + sizeof(SkSFNTHeader)) + tableIndex; - nameTableEntry->logicalLength = SkEndian_SwapBE32(nameTableLogicalSize); - nameTableEntry->offset = SkEndian_SwapBE32(originalDataSize); + nameTableEntry->logicalLength = SkEndian_SwapBE32(SkToU32(nameTableLogicalSize)); + nameTableEntry->offset = SkEndian_SwapBE32(SkToU32(originalDataSize)); // Write the new 'name' table after the original font data. SkOTTableName* nameTable = reinterpret_cast<SkOTTableName*>(data + originalDataSize); |