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

Side by Side Diff: src/hdmx.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/gasp.cc ('k') | src/kern.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 "hdmx.h" 5 #include "hdmx.h"
6 #include "head.h" 6 #include "head.h"
7 #include "maxp.h" 7 #include "maxp.h"
8 8
9 // hdmx - Horizontal Device Metrics 9 // hdmx - Horizontal Device Metrics
10 // http://www.microsoft.com/opentype/otspec/hdmx.htm 10 // http://www.microsoft.com/opentype/otspec/hdmx.htm
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 bool ots_hdmx_should_serialise(OpenTypeFile *file) { 99 bool ots_hdmx_should_serialise(OpenTypeFile *file) {
100 if (!file->hdmx) return false; 100 if (!file->hdmx) return false;
101 if (!file->glyf) return false; // this table is not for CFF fonts. 101 if (!file->glyf) return false; // this table is not for CFF fonts.
102 return true; 102 return true;
103 } 103 }
104 104
105 bool ots_hdmx_serialise(OTSStream *out, OpenTypeFile *file) { 105 bool ots_hdmx_serialise(OTSStream *out, OpenTypeFile *file) {
106 OpenTypeHDMX * const hdmx = file->hdmx; 106 OpenTypeHDMX * const hdmx = file->hdmx;
107 107
108 if (!out->WriteU16(hdmx->version) || 108 const int16_t num_recs = static_cast<int16_t>(hdmx->records.size());
109 !out->WriteS16(hdmx->records.size()) || 109 if (hdmx->records.size() >
110 static_cast<size_t>(std::numeric_limits<int16_t>::max()) ||
111 !out->WriteU16(hdmx->version) ||
112 !out->WriteS16(num_recs) ||
110 !out->WriteS32(hdmx->size_device_record)) { 113 !out->WriteS32(hdmx->size_device_record)) {
111 return OTS_FAILURE(); 114 return OTS_FAILURE();
112 } 115 }
113 116
114 for (unsigned i = 0; i < hdmx->records.size(); ++i) { 117 for (int16_t i = 0; i < num_recs; ++i) {
115 const OpenTypeHDMXDeviceRecord& rec = hdmx->records[i]; 118 const OpenTypeHDMXDeviceRecord& rec = hdmx->records[i];
116 if (!out->Write(&rec.pixel_size, 1) || 119 if (!out->Write(&rec.pixel_size, 1) ||
117 !out->Write(&rec.max_width, 1) || 120 !out->Write(&rec.max_width, 1) ||
118 !out->Write(&rec.widths[0], rec.widths.size())) { 121 !out->Write(&rec.widths[0], rec.widths.size())) {
119 return OTS_FAILURE(); 122 return OTS_FAILURE();
120 } 123 }
121 if ((hdmx->pad_len > 0) && 124 if ((hdmx->pad_len > 0) &&
122 !out->Write((const uint8_t *)"\x00\x00\x00", hdmx->pad_len)) { 125 !out->Write((const uint8_t *)"\x00\x00\x00", hdmx->pad_len)) {
123 return OTS_FAILURE(); 126 return OTS_FAILURE();
124 } 127 }
125 } 128 }
126 129
127 return true; 130 return true;
128 } 131 }
129 132
130 void ots_hdmx_free(OpenTypeFile *file) { 133 void ots_hdmx_free(OpenTypeFile *file) {
131 delete file->hdmx; 134 delete file->hdmx;
132 } 135 }
133 136
134 } // namespace ots 137 } // namespace ots
OLDNEW
« no previous file with comments | « src/gasp.cc ('k') | src/kern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698