Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: src/core/SkValidatingReadBuffer.cpp

Issue 37803002: Adding size parameter to read array functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: More uint32_t to size_t changes Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkValidatingReadBuffer.h ('k') | src/effects/SkBicubicImageFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkValidatingReadBuffer.cpp
diff --git a/src/core/SkValidatingReadBuffer.cpp b/src/core/SkValidatingReadBuffer.cpp
index 323273d131a25d80a84d0aa671aea023f1c9f501..1331221588ca6bcb20c4e07e014791d0968fa254 100644
--- a/src/core/SkValidatingReadBuffer.cpp
+++ b/src/core/SkValidatingReadBuffer.cpp
@@ -149,58 +149,68 @@ void SkValidatingReadBuffer::readPath(SkPath* path) {
}
}
-uint32_t SkValidatingReadBuffer::readByteArray(void* value) {
- const uint32_t length = this->readUInt();
+bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) {
+ const uint32_t length = this->getArrayCount();
+ fError = fError || (size != length);
+ (void)this->skip(sizeof(uint32_t)); // Skip array count
sugoi1 2013/10/30 18:14:32 Here, the reason why I changed readUInt() for : 1
const void* ptr = this->skip(SkAlign4(length));
if (!fError) {
memcpy(value, ptr, length);
- return length;
+ return true;
}
- return 0;
+ return false;
}
-uint32_t SkValidatingReadBuffer::readColorArray(SkColor* colors) {
- const uint32_t count = this->readUInt();
- const uint32_t byteLength = count * sizeof(SkColor);
+bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) {
+ const uint32_t count = this->getArrayCount();
+ const size_t byteLength = count * sizeof(SkColor);
+ fError = fError || (size != byteLength);
+ (void)this->skip(sizeof(uint32_t)); // Skip array count
const void* ptr = this->skip(SkAlign4(byteLength));
if (!fError) {
memcpy(colors, ptr, byteLength);
- return count;
+ return true;
}
- return 0;
+ return false;
}
-uint32_t SkValidatingReadBuffer::readIntArray(int32_t* values) {
- const uint32_t count = this->readUInt();
- const uint32_t byteLength = count * sizeof(int32_t);
+bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) {
+ const uint32_t count = this->getArrayCount();
+ const size_t byteLength = count * sizeof(int32_t);
+ fError = fError || (size != byteLength);
+ (void)this->skip(sizeof(uint32_t)); // Skip array count
const void* ptr = this->skip(SkAlign4(byteLength));
if (!fError) {
memcpy(values, ptr, byteLength);
- return count;
+ return true;
}
- return 0;
+ return false;
}
-uint32_t SkValidatingReadBuffer::readPointArray(SkPoint* points) {
- const uint32_t count = this->readUInt();
- const uint32_t byteLength = count * sizeof(SkPoint);
+bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) {
+ const uint32_t count = this->getArrayCount();
+ const size_t byteLength = count * sizeof(SkPoint);
+ fError = fError || (size != byteLength);
+ (void)this->skip(sizeof(uint32_t)); // Skip array count
const void* ptr = this->skip(SkAlign4(byteLength));
if (!fError) {
memcpy(points, ptr, byteLength);
- return count;
+ return true;
}
- return 0;
+ return false;
}
-uint32_t SkValidatingReadBuffer::readScalarArray(SkScalar* values) {
- const uint32_t count = this->readUInt();
- const uint32_t byteLength = count * sizeof(SkScalar);
+bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) {
+ const uint32_t count = this->getArrayCount();
+ const size_t byteLength = count * sizeof(SkScalar);
+ fError = fError || (size != byteLength);
+ (void)this->skip(sizeof(uint32_t)); // Skip array count
const void* ptr = this->skip(SkAlign4(byteLength));
if (!fError) {
memcpy(values, ptr, byteLength);
- return count;
+ return true;
}
- return 0;
+ return false;
}
uint32_t SkValidatingReadBuffer::getArrayCount() {
« no previous file with comments | « src/core/SkValidatingReadBuffer.h ('k') | src/effects/SkBicubicImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698