OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkBuffer.h" | 8 #include "SkBuffer.h" |
9 | 9 |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 ////////////////////////////////////////////////////////////////////////////////
//////// | 12 ////////////////////////////////////////////////////////////////////////////////
//////// |
13 | 13 |
14 void SkRBuffer::readNoSizeCheck(void* buffer, size_t size) | 14 void SkRBuffer::readNoSizeCheck(void* buffer, size_t size) |
15 { | 15 { |
16 SkASSERT((fData != 0 && fStop == 0) || fPos + size <= fStop); | 16 SkASSERT((fData != 0 && fStop == 0) || fPos + size <= fStop); |
17 if (buffer) | 17 if (buffer) |
18 memcpy(buffer, fPos, size); | 18 memcpy(buffer, fPos, size); |
19 fPos += size; | 19 fPos += size; |
20 } | 20 } |
21 | 21 |
22 const void* SkRBuffer::skip(size_t size) | 22 const void* SkRBuffer::skip(size_t size) |
23 { | 23 { |
24 const void* result = fPos; | 24 const void* result = fPos; |
25 readNoSizeCheck(NULL, size); | 25 readNoSizeCheck(nullptr, size); |
26 return result; | 26 return result; |
27 } | 27 } |
28 | 28 |
29 size_t SkRBuffer::skipToAlign4() | 29 size_t SkRBuffer::skipToAlign4() |
30 { | 30 { |
31 size_t pos = this->pos(); | 31 size_t pos = this->pos(); |
32 size_t n = SkAlign4(pos) - pos; | 32 size_t n = SkAlign4(pos) - pos; |
33 fPos += n; | 33 fPos += n; |
34 return n; | 34 return n; |
35 } | 35 } |
36 | 36 |
37 bool SkRBufferWithSizeCheck::read(void* buffer, size_t size) { | 37 bool SkRBufferWithSizeCheck::read(void* buffer, size_t size) { |
38 fError = fError || (fPos + size > fStop); | 38 fError = fError || (fPos + size > fStop); |
39 if (!fError && (size > 0)) { | 39 if (!fError && (size > 0)) { |
40 readNoSizeCheck(buffer, size); | 40 readNoSizeCheck(buffer, size); |
41 } | 41 } |
42 return !fError; | 42 return !fError; |
43 } | 43 } |
44 | 44 |
45 void* SkWBuffer::skip(size_t size) | 45 void* SkWBuffer::skip(size_t size) |
46 { | 46 { |
47 void* result = fPos; | 47 void* result = fPos; |
48 writeNoSizeCheck(NULL, size); | 48 writeNoSizeCheck(nullptr, size); |
49 return fData == NULL ? NULL : result; | 49 return fData == nullptr ? nullptr : result; |
50 } | 50 } |
51 | 51 |
52 void SkWBuffer::writeNoSizeCheck(const void* buffer, size_t size) | 52 void SkWBuffer::writeNoSizeCheck(const void* buffer, size_t size) |
53 { | 53 { |
54 SkASSERT(fData == 0 || fStop == 0 || fPos + size <= fStop); | 54 SkASSERT(fData == 0 || fStop == 0 || fPos + size <= fStop); |
55 if (fData && buffer) | 55 if (fData && buffer) |
56 memcpy(fPos, buffer, size); | 56 memcpy(fPos, buffer, size); |
57 fPos += size; | 57 fPos += size; |
58 } | 58 } |
59 | 59 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 const void* sk_buffer_read_ptr(const void* buffer, void** ptr) | 129 const void* sk_buffer_read_ptr(const void* buffer, void** ptr) |
130 { | 130 { |
131 AssertBuffer32(buffer); | 131 AssertBuffer32(buffer); |
132 if (ptr) | 132 if (ptr) |
133 *ptr = *(void**)buffer; | 133 *ptr = *(void**)buffer; |
134 return (const char*)buffer + sizeof(void*); | 134 return (const char*)buffer + sizeof(void*); |
135 } | 135 } |
136 | 136 |
137 #endif | 137 #endif |
OLD | NEW |