OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2009 The Android Open Source Project | 3 * Copyright 2009 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
85 | 85 |
86 SkColorTable::SkColorTable(SkFlattenableReadBuffer& buffer) { | 86 SkColorTable::SkColorTable(SkFlattenableReadBuffer& buffer) { |
87 f16BitCache = NULL; | 87 f16BitCache = NULL; |
88 SkDEBUGCODE(fColorLockCount = 0;) | 88 SkDEBUGCODE(fColorLockCount = 0;) |
89 SkDEBUGCODE(f16BitCacheLockCount = 0;) | 89 SkDEBUGCODE(f16BitCacheLockCount = 0;) |
90 | 90 |
91 fAlphaType = SkToU8(buffer.readUInt()); | 91 fAlphaType = SkToU8(buffer.readUInt()); |
92 fCount = buffer.getArrayCount(); | 92 fCount = buffer.getArrayCount(); |
93 fColors = (SkPMColor*)sk_malloc_throw(fCount * sizeof(SkPMColor)); | 93 size_t allocSize = fCount * sizeof(SkPMColor); |
94 SkDEBUGCODE(bool success =) buffer.readColorArray(fColors, fCount); | 94 SkDEBUGCODE(bool success = false;) |
| 95 if (buffer.validate(buffer.isAvailable(allocSize))) { |
| 96 fColors = (SkPMColor*)sk_malloc_throw(allocSize); |
| 97 SkDEBUGCODE(success =) buffer.readColorArray(fColors, fCount); |
| 98 } else { |
| 99 fCount = 0; |
| 100 fColors = NULL; |
| 101 } |
95 #ifdef SK_DEBUG | 102 #ifdef SK_DEBUG |
96 SkASSERT((unsigned)fCount <= 256); | 103 SkASSERT((unsigned)fCount <= 256); |
97 SkASSERT(success); | 104 SkASSERT(success); |
98 #endif | 105 #endif |
99 } | 106 } |
100 | 107 |
101 void SkColorTable::writeToBuffer(SkFlattenableWriteBuffer& buffer) const { | 108 void SkColorTable::writeToBuffer(SkFlattenableWriteBuffer& buffer) const { |
102 buffer.writeUInt(fAlphaType); | 109 buffer.writeUInt(fAlphaType); |
103 buffer.writeColorArray(fColors, fCount); | 110 buffer.writeColorArray(fColors, fCount); |
104 } | 111 } |
OLD | NEW |