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

Unified Diff: src/core/SkOrderedReadBuffer.cpp

Issue 37803002: Adding size parameter to read array functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed comments 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
Index: src/core/SkOrderedReadBuffer.cpp
diff --git a/src/core/SkOrderedReadBuffer.cpp b/src/core/SkOrderedReadBuffer.cpp
index d9aa8bd1d751d35c722bb05d79ddd291d0225461..31841182b9c47edbce0e0f85b1b9bef466620fe8 100644
--- a/src/core/SkOrderedReadBuffer.cpp
+++ b/src/core/SkOrderedReadBuffer.cpp
@@ -137,38 +137,37 @@ void SkOrderedReadBuffer::readPath(SkPath* path) {
fReader.readPath(path);
}
-uint32_t SkOrderedReadBuffer::readByteArray(void* value) {
- const uint32_t length = fReader.readU32();
- memcpy(value, fReader.skip(SkAlign4(length)), length);
- return length;
+bool SkOrderedReadBuffer::readArray(void* value, size_t size, size_t elementSize) {
+ const size_t count = this->getArrayCount();
+ if (count == size) {
Stephen White 2013/10/31 15:19:28 Nit: prefer the early-out to be the error case rat
+ (void)fReader.skip(sizeof(uint32_t)); // Skip array count
+ const size_t byteLength = count * elementSize;
Stephen White 2013/10/31 15:19:28 Should we be checking for overflow here? At worst,
+ memcpy(value, fReader.skip(SkAlign4(byteLength)), byteLength);
+ return true;
+ }
+ SkASSERT(false);
+ fReader.skip(fReader.available());
+ return false;
+}
+
+bool SkOrderedReadBuffer::readByteArray(void* value, size_t size) {
+ return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned char));
}
-uint32_t SkOrderedReadBuffer::readColorArray(SkColor* colors) {
- const uint32_t count = fReader.readU32();
- const uint32_t byteLength = count * sizeof(SkColor);
- memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength);
- return count;
+bool SkOrderedReadBuffer::readColorArray(SkColor* colors, size_t size) {
+ return readArray(colors, size, sizeof(SkColor));
}
-uint32_t SkOrderedReadBuffer::readIntArray(int32_t* values) {
- const uint32_t count = fReader.readU32();
- const uint32_t byteLength = count * sizeof(int32_t);
- memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength);
- return count;
+bool SkOrderedReadBuffer::readIntArray(int32_t* values, size_t size) {
+ return readArray(values, size, sizeof(int32_t));
}
-uint32_t SkOrderedReadBuffer::readPointArray(SkPoint* points) {
- const uint32_t count = fReader.readU32();
- const uint32_t byteLength = count * sizeof(SkPoint);
- memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength);
- return count;
+bool SkOrderedReadBuffer::readPointArray(SkPoint* points, size_t size) {
+ return readArray(points, size, sizeof(SkPoint));
}
-uint32_t SkOrderedReadBuffer::readScalarArray(SkScalar* values) {
- const uint32_t count = fReader.readU32();
- const uint32_t byteLength = count * sizeof(SkScalar);
- memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength);
- return count;
+bool SkOrderedReadBuffer::readScalarArray(SkScalar* values, size_t size) {
+ return readArray(values, size, sizeof(SkScalar));
}
uint32_t SkOrderedReadBuffer::getArrayCount() {

Powered by Google App Engine
This is Rietveld 408576698