[go: nahoru, domu]

fix size_t/int warnings

BUG=skia:
R=mtklein@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/247753003

git-svn-id: http://skia.googlecode.com/svn/trunk/src@14332 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkReadBuffer.cpp b/core/SkReadBuffer.cpp
index b60dee3..b4bc875 100644
--- a/core/SkReadBuffer.cpp
+++ b/core/SkReadBuffer.cpp
@@ -321,10 +321,10 @@
     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/core/SkRegion.cpp b/core/SkRegion.cpp
index baedf2a..98670b6 100644
--- a/core/SkRegion.cpp
+++ b/core/SkRegion.cpp
@@ -796,7 +796,7 @@
                 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 @@
 
             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/core/SkRegionPriv.h b/core/SkRegionPriv.h
index f299f3a..c8f000d 100644
--- a/core/SkRegionPriv.h
+++ b/core/SkRegionPriv.h
@@ -29,7 +29,7 @@
         SkASSERT(curr[1] < SkRegion::kRunTypeSentinel);
         curr += 2;
     }
-    return (curr - runs) >> 1;
+    return SkToInt((curr - runs) >> 1);
 }
 #endif
 
@@ -213,7 +213,7 @@
 
 #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/core/SkScalerContext.cpp b/core/SkScalerContext.cpp
index d0d24ee..fee1ff7 100644
--- a/core/SkScalerContext.cpp
+++ b/core/SkScalerContext.cpp
@@ -548,8 +548,9 @@
     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/core/SkStream.cpp b/core/SkStream.cpp
index c60f2a7..ebaac9a 100644
--- a/core/SkStream.cpp
+++ b/core/SkStream.cpp
@@ -161,7 +161,7 @@
         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::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 @@
 {
 }
 
-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 @@
         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 @@
                 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/core/SkValidatingReadBuffer.cpp b/core/SkValidatingReadBuffer.cpp
index 8db2c68..95bf83c 100644
--- a/core/SkValidatingReadBuffer.cpp
+++ b/core/SkValidatingReadBuffer.cpp
@@ -256,10 +256,10 @@
     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/core/SkWriter32.cpp b/core/SkWriter32.cpp
index c7bfd92..3397c37 100644
--- a/core/SkWriter32.cpp
+++ b/core/SkWriter32.cpp
@@ -47,7 +47,7 @@
 
     // [ 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/sfnt/SkOTUtils.cpp b/sfnt/SkOTUtils.cpp
index 004a888..e76d1da 100644
--- a/sfnt/SkOTUtils.cpp
+++ b/sfnt/SkOTUtils.cpp
@@ -103,7 +103,7 @@
     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 @@
 
     // 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);