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

Side by Side Diff: src/kern.cc

Issue 512923003: Fix MSVC warnings about possible value truncation. (Closed) Base URL: https://chromium.googlesource.com/external/ots.git@master
Patch Set: Created 6 years, 3 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 | « src/hdmx.cc ('k') | src/loca.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 (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 #include "kern.h" 5 #include "kern.h"
6 6
7 // kern - Kerning 7 // kern - Kerning
8 // http://www.microsoft.com/opentype/otspec/kern.htm 8 // http://www.microsoft.com/opentype/otspec/kern.htm
9 9
10 #define DROP_THIS_TABLE \ 10 #define DROP_THIS_TABLE \
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 ++max_pow2; 104 ++max_pow2;
105 } 105 }
106 const uint16_t expected_search_range = (1u << max_pow2) * kFormat0PairSize; 106 const uint16_t expected_search_range = (1u << max_pow2) * kFormat0PairSize;
107 if (subtable.search_range != expected_search_range) { 107 if (subtable.search_range != expected_search_range) {
108 OTS_WARNING("bad search range"); 108 OTS_WARNING("bad search range");
109 subtable.search_range = expected_search_range; 109 subtable.search_range = expected_search_range;
110 } 110 }
111 if (subtable.entry_selector != max_pow2) { 111 if (subtable.entry_selector != max_pow2) {
112 return OTS_FAILURE(); 112 return OTS_FAILURE();
113 } 113 }
114 const uint32_t expected_range_shift 114 const uint16_t expected_range_shift =
115 = kFormat0PairSize * num_pairs - subtable.search_range; 115 kFormat0PairSize * num_pairs - subtable.search_range;
116 if (subtable.range_shift != expected_range_shift) { 116 if (subtable.range_shift != expected_range_shift) {
117 OTS_WARNING("bad range shift"); 117 OTS_WARNING("bad range shift");
118 subtable.range_shift = expected_range_shift; 118 subtable.range_shift = expected_range_shift;
119 } 119 }
120 120
121 // Read kerning pairs. 121 // Read kerning pairs.
122 subtable.pairs.reserve(num_pairs); 122 subtable.pairs.reserve(num_pairs);
123 uint32_t last_pair = 0; 123 uint32_t last_pair = 0;
124 for (unsigned j = 0; j < num_pairs; ++j) { 124 for (unsigned j = 0; j < num_pairs; ++j) {
125 OpenTypeKERNFormat0Pair kerning_pair; 125 OpenTypeKERNFormat0Pair kerning_pair;
(...skipping 28 matching lines...) Expand all
154 } 154 }
155 155
156 bool ots_kern_should_serialise(OpenTypeFile *file) { 156 bool ots_kern_should_serialise(OpenTypeFile *file) {
157 if (!file->glyf) return false; // this table is not for CFF fonts. 157 if (!file->glyf) return false; // this table is not for CFF fonts.
158 return file->kern != NULL; 158 return file->kern != NULL;
159 } 159 }
160 160
161 bool ots_kern_serialise(OTSStream *out, OpenTypeFile *file) { 161 bool ots_kern_serialise(OTSStream *out, OpenTypeFile *file) {
162 const OpenTypeKERN *kern = file->kern; 162 const OpenTypeKERN *kern = file->kern;
163 163
164 if (!out->WriteU16(kern->version) || 164 const uint16_t num_subtables = static_cast<uint16_t>(kern->subtables.size());
165 !out->WriteU16(kern->subtables.size())) { 165 if (num_subtables != kern->subtables.size() ||
166 !out->WriteU16(kern->version) ||
167 !out->WriteU16(num_subtables)) {
166 return OTS_FAILURE(); 168 return OTS_FAILURE();
167 } 169 }
168 170
169 for (unsigned i = 0; i < kern->subtables.size(); ++i) { 171 for (uint16_t i = 0; i < num_subtables; ++i) {
170 const uint16_t length = 14 + (6 * kern->subtables[i].pairs.size()); 172 const size_t length = 14 + (6 * kern->subtables[i].pairs.size());
171 if (!out->WriteU16(kern->subtables[i].version) || 173 if (length > std::numeric_limits<uint16_t>::max() ||
172 !out->WriteU16(length) || 174 !out->WriteU16(kern->subtables[i].version) ||
175 !out->WriteU16(static_cast<uint16_t>(length)) ||
173 !out->WriteU16(kern->subtables[i].coverage) || 176 !out->WriteU16(kern->subtables[i].coverage) ||
174 !out->WriteU16(kern->subtables[i].pairs.size()) || 177 !out->WriteU16(
178 static_cast<uint16_t>(kern->subtables[i].pairs.size())) ||
175 !out->WriteU16(kern->subtables[i].search_range) || 179 !out->WriteU16(kern->subtables[i].search_range) ||
176 !out->WriteU16(kern->subtables[i].entry_selector) || 180 !out->WriteU16(kern->subtables[i].entry_selector) ||
177 !out->WriteU16(kern->subtables[i].range_shift)) { 181 !out->WriteU16(kern->subtables[i].range_shift)) {
178 return OTS_FAILURE(); 182 return OTS_FAILURE();
179 } 183 }
180 for (unsigned j = 0; j < kern->subtables[i].pairs.size(); ++j) { 184 for (unsigned j = 0; j < kern->subtables[i].pairs.size(); ++j) {
181 if (!out->WriteU16(kern->subtables[i].pairs[j].left) || 185 if (!out->WriteU16(kern->subtables[i].pairs[j].left) ||
182 !out->WriteU16(kern->subtables[i].pairs[j].right) || 186 !out->WriteU16(kern->subtables[i].pairs[j].right) ||
183 !out->WriteS16(kern->subtables[i].pairs[j].value)) { 187 !out->WriteS16(kern->subtables[i].pairs[j].value)) {
184 return OTS_FAILURE(); 188 return OTS_FAILURE();
185 } 189 }
186 } 190 }
187 } 191 }
188 192
189 return true; 193 return true;
190 } 194 }
191 195
192 void ots_kern_free(OpenTypeFile *file) { 196 void ots_kern_free(OpenTypeFile *file) {
193 delete file->kern; 197 delete file->kern;
194 } 198 }
195 199
196 } // namespace ots 200 } // namespace ots
OLDNEW
« no previous file with comments | « src/hdmx.cc ('k') | src/loca.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698