OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef OPENTYPE_SANITISER_H_ | 5 #ifndef OPENTYPE_SANITISER_H_ |
6 #define OPENTYPE_SANITISER_H_ | 6 #define OPENTYPE_SANITISER_H_ |
7 | 7 |
8 #if defined(_WIN32) | 8 #if defined(_WIN32) |
9 typedef signed char int8_t; | 9 typedef signed char int8_t; |
10 typedef unsigned char uint8_t; | 10 typedef unsigned char uint8_t; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 if (chksum_buffer_offset_) { | 50 if (chksum_buffer_offset_) { |
51 const size_t l = | 51 const size_t l = |
52 std::min(length, static_cast<size_t>(4) - chksum_buffer_offset_); | 52 std::min(length, static_cast<size_t>(4) - chksum_buffer_offset_); |
53 std::memcpy(chksum_buffer_ + chksum_buffer_offset_, data, l); | 53 std::memcpy(chksum_buffer_ + chksum_buffer_offset_, data, l); |
54 chksum_buffer_offset_ += l; | 54 chksum_buffer_offset_ += l; |
55 offset += l; | 55 offset += l; |
56 length -= l; | 56 length -= l; |
57 } | 57 } |
58 | 58 |
59 if (chksum_buffer_offset_ == 4) { | 59 if (chksum_buffer_offset_ == 4) { |
60 // TODO(yusukes): This cast breaks the strict-aliasing rule. | 60 uint32_t chksum; |
61 chksum_ += ntohl(*reinterpret_cast<const uint32_t*>(chksum_buffer_)); | 61 std::memcpy(&chksum, chksum_buffer_, 4); |
| 62 chksum_ += ntohl(chksum); |
62 chksum_buffer_offset_ = 0; | 63 chksum_buffer_offset_ = 0; |
63 } | 64 } |
64 | 65 |
65 while (length >= 4) { | 66 while (length >= 4) { |
66 chksum_ += ntohl(*reinterpret_cast<const uint32_t*>( | 67 chksum_ += ntohl(*reinterpret_cast<const uint32_t*>( |
67 reinterpret_cast<const uint8_t*>(data) + offset)); | 68 reinterpret_cast<const uint8_t*>(data) + offset)); |
68 length -= 4; | 69 length -= 4; |
69 offset += 4; | 70 offset += 4; |
70 } | 71 } |
71 | 72 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // ----------------------------------------------------------------------------- | 183 // ----------------------------------------------------------------------------- |
183 bool Process(OTSStream *output, const uint8_t *input, size_t length); | 184 bool Process(OTSStream *output, const uint8_t *input, size_t length); |
184 | 185 |
185 // Force to disable debug output even when the library is compiled with | 186 // Force to disable debug output even when the library is compiled with |
186 // -DOTS_DEBUG. | 187 // -DOTS_DEBUG. |
187 void DisableDebugOutput(); | 188 void DisableDebugOutput(); |
188 | 189 |
189 } // namespace ots | 190 } // namespace ots |
190 | 191 |
191 #endif // OPENTYPE_SANITISER_H_ | 192 #endif // OPENTYPE_SANITISER_H_ |
OLD | NEW |