| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
| 10 #include "SkValidatingReadBuffer.h" | 10 #include "SkValidatingReadBuffer.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 const size_t alignedSize = SkAlign4(len + 1); | 103 const size_t alignedSize = SkAlign4(len + 1); |
| 104 this->skip(alignedSize); | 104 this->skip(alignedSize); |
| 105 if (!fError) { | 105 if (!fError) { |
| 106 this->validate(cptr[len] == '\0'); | 106 this->validate(cptr[len] == '\0'); |
| 107 } | 107 } |
| 108 if (!fError) { | 108 if (!fError) { |
| 109 string->set(cptr, len); | 109 string->set(cptr, len); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 void SkValidatingReadBuffer::readColor4f(SkColor4f* color) { |
| 114 const void* ptr = this->skip(sizeof(SkColor4f)); |
| 115 if (!fError) { |
| 116 memcpy(color, ptr, sizeof(SkColor4f)); |
| 117 } |
| 118 } |
| 119 |
| 113 void SkValidatingReadBuffer::readPoint(SkPoint* point) { | 120 void SkValidatingReadBuffer::readPoint(SkPoint* point) { |
| 114 point->fX = this->readScalar(); | 121 point->fX = this->readScalar(); |
| 115 point->fY = this->readScalar(); | 122 point->fY = this->readScalar(); |
| 116 } | 123 } |
| 117 | 124 |
| 118 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { | 125 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { |
| 119 size_t size = 0; | 126 size_t size = 0; |
| 120 if (!fError) { | 127 if (!fError) { |
| 121 size = matrix->readFromMemory(fReader.peek(), fReader.available()); | 128 size = matrix->readFromMemory(fReader.peek(), fReader.available()); |
| 122 this->validate((SkAlign4(size) == size) && (0 != size)); | 129 this->validate((SkAlign4(size) == size) && (0 != size)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 197 } |
| 191 | 198 |
| 192 bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) { | 199 bool SkValidatingReadBuffer::readByteArray(void* value, size_t size) { |
| 193 return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned c
har)); | 200 return readArray(static_cast<unsigned char*>(value), size, sizeof(unsigned c
har)); |
| 194 } | 201 } |
| 195 | 202 |
| 196 bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) { | 203 bool SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) { |
| 197 return readArray(colors, size, sizeof(SkColor)); | 204 return readArray(colors, size, sizeof(SkColor)); |
| 198 } | 205 } |
| 199 | 206 |
| 207 bool SkValidatingReadBuffer::readColor4fArray(SkColor4f* colors, size_t size) { |
| 208 return readArray(colors, size, sizeof(SkColor4f)); |
| 209 } |
| 210 |
| 200 bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) { | 211 bool SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) { |
| 201 return readArray(values, size, sizeof(int32_t)); | 212 return readArray(values, size, sizeof(int32_t)); |
| 202 } | 213 } |
| 203 | 214 |
| 204 bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) { | 215 bool SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) { |
| 205 return readArray(points, size, sizeof(SkPoint)); | 216 return readArray(points, size, sizeof(SkPoint)); |
| 206 } | 217 } |
| 207 | 218 |
| 208 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { | 219 bool SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
| 209 return readArray(values, size, sizeof(SkScalar)); | 220 return readArray(values, size, sizeof(SkScalar)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 size_t offset = fReader.offset(); | 286 size_t offset = fReader.offset(); |
| 276 obj = (*factory)(*this); | 287 obj = (*factory)(*this); |
| 277 // check that we read the amount we expected | 288 // check that we read the amount we expected |
| 278 size_t sizeRead = fReader.offset() - offset; | 289 size_t sizeRead = fReader.offset() - offset; |
| 279 this->validate(sizeRecorded == sizeRead); | 290 this->validate(sizeRecorded == sizeRead); |
| 280 if (fError) { | 291 if (fError) { |
| 281 obj = nullptr; | 292 obj = nullptr; |
| 282 } | 293 } |
| 283 return obj.release(); | 294 return obj.release(); |
| 284 } | 295 } |
| OLD | NEW |