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

Side by Side Diff: third_party/woff2/src/buffer.h

Issue 2736873002: Update woff2 to cbea7b9 (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « third_party/woff2/README.chromium ('k') | third_party/woff2/src/convert_woff2ttf_fuzzer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 Google Inc. All Rights Reserved. 1 // Copyright 2013 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 // ----------------------------------------------------------------------------- 59 // -----------------------------------------------------------------------------
60 // Buffer helper class 60 // Buffer helper class
61 // 61 //
62 // This class perform some trival buffer operations while checking for 62 // This class perform some trival buffer operations while checking for
63 // out-of-bounds errors. As a family they return false if anything is amiss, 63 // out-of-bounds errors. As a family they return false if anything is amiss,
64 // updating the current offset otherwise. 64 // updating the current offset otherwise.
65 // ----------------------------------------------------------------------------- 65 // -----------------------------------------------------------------------------
66 class Buffer { 66 class Buffer {
67 public: 67 public:
68 Buffer(const uint8_t *buffer, size_t len) 68 Buffer(const uint8_t *data, size_t len)
69 : buffer_(buffer), 69 : buffer_(data),
70 length_(len), 70 length_(len),
71 offset_(0) { } 71 offset_(0) { }
72 72
73 bool Skip(size_t n_bytes) { 73 bool Skip(size_t n_bytes) {
74 return Read(NULL, n_bytes); 74 return Read(NULL, n_bytes);
75 } 75 }
76 76
77 bool Read(uint8_t *buffer, size_t n_bytes) { 77 bool Read(uint8_t *data, size_t n_bytes) {
78 if (n_bytes > 1024 * 1024 * 1024) { 78 if (n_bytes > 1024 * 1024 * 1024) {
79 return FONT_COMPRESSION_FAILURE(); 79 return FONT_COMPRESSION_FAILURE();
80 } 80 }
81 if ((offset_ + n_bytes > length_) || 81 if ((offset_ + n_bytes > length_) ||
82 (offset_ > length_ - n_bytes)) { 82 (offset_ > length_ - n_bytes)) {
83 return FONT_COMPRESSION_FAILURE(); 83 return FONT_COMPRESSION_FAILURE();
84 } 84 }
85 if (buffer) { 85 if (data) {
86 std::memcpy(buffer, buffer_ + offset_, n_bytes); 86 std::memcpy(data, buffer_ + offset_, n_bytes);
87 } 87 }
88 offset_ += n_bytes; 88 offset_ += n_bytes;
89 return true; 89 return true;
90 } 90 }
91 91
92 inline bool ReadU8(uint8_t *value) { 92 inline bool ReadU8(uint8_t *value) {
93 if (offset_ + 1 > length_) { 93 if (offset_ + 1 > length_) {
94 return FONT_COMPRESSION_FAILURE(); 94 return FONT_COMPRESSION_FAILURE();
95 } 95 }
96 *value = buffer_[offset_]; 96 *value = buffer_[offset_];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 private: 164 private:
165 const uint8_t * const buffer_; 165 const uint8_t * const buffer_;
166 const size_t length_; 166 const size_t length_;
167 size_t offset_; 167 size_t offset_;
168 }; 168 };
169 169
170 } // namespace woff2 170 } // namespace woff2
171 171
172 #endif // WOFF2_BUFFER_H_ 172 #endif // WOFF2_BUFFER_H_
OLDNEW
« no previous file with comments | « third_party/woff2/README.chromium ('k') | third_party/woff2/src/convert_woff2ttf_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698