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

Unified Diff: src/post.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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ots.cc ('k') | src/vorg.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/post.cc
diff --git a/src/post.cc b/src/post.cc
index f4a0b0def778ab17ffe9be46d608a747b5f33458..44c2c7ddbad2e1a78341d1ca363823223f626375 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -146,11 +146,14 @@ bool ots_post_serialise(OTSStream *out, OpenTypeFile *file) {
return true; // v1.0 and v3.0 does not have glyph names.
}
- if (!out->WriteU16(post->glyph_name_index.size())) {
+ const uint16_t num_indexes =
+ static_cast<uint16_t>(post->glyph_name_index.size());
+ if (num_indexes != post->glyph_name_index.size() ||
+ !out->WriteU16(num_indexes)) {
return OTS_FAILURE();
}
- for (unsigned i = 0; i < post->glyph_name_index.size(); ++i) {
+ for (uint16_t i = 0; i < num_indexes; ++i) {
if (!out->WriteU16(post->glyph_name_index[i])) {
return OTS_FAILURE();
}
@@ -159,8 +162,9 @@ bool ots_post_serialise(OTSStream *out, OpenTypeFile *file) {
// Now we just have to write out the strings in the correct order
for (unsigned i = 0; i < post->names.size(); ++i) {
const std::string& s = post->names[i];
- const uint8_t string_length = s.size();
- if (!out->Write(&string_length, 1)) {
+ const uint8_t string_length = static_cast<uint8_t>(s.size());
+ if (string_length != s.size() ||
+ !out->Write(&string_length, 1)) {
return OTS_FAILURE();
}
// Some ttf fonts (e.g., frank.ttf on Windows Vista) have zero-length name.
« no previous file with comments | « src/ots.cc ('k') | src/vorg.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698