Bug 699420 - Update OTS to r74; r=jfkthame
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 04 Nov 2011 01:26:56 +0000
changeset 79719 8a07735ec31e6d915380a008c0e6280f30fffb37
parent 79718 2964292c2dc7d55342f016f132f5573d21a7731f
child 79720 b31507c8ca17ba5300135527404a9baf4fc287a4
push id3111
push userbmo@edmorley.co.uk
push dateFri, 04 Nov 2011 01:27:50 +0000
treeherdermozilla-inbound@8a07735ec31e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs699420
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 699420 - Update OTS to r74; r=jfkthame
gfx/ots/README.mozilla
gfx/ots/include/opentype-sanitiser.h
gfx/ots/ots-fix-gcc46.patch
gfx/ots/src/cff.cc
gfx/ots/src/cmap.cc
gfx/ots/src/gdef.cc
gfx/ots/src/glyf.cc
gfx/ots/src/gpos.cc
gfx/ots/src/gsub.cc
gfx/ots/src/layout.cc
gfx/ots/src/name.cc
gfx/ots/src/name.h
gfx/ots/src/os2.cc
gfx/ots/src/ots.cc
gfx/ots/src/ots.h
--- a/gfx/ots/README.mozilla
+++ b/gfx/ots/README.mozilla
@@ -1,10 +1,8 @@
 This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/.
 
-Current revision: r62
+Current revision: r74
 
 Applied local patches:
     ots-fix-vc10.patch - workaround for VS10 STL wrappers (bug 602558)
 
-    ots-fix-gcc46.patch - fix os2.cc compile error for GCC 4.6 (bug 628252)
-
     ots-fix-sparc64.patch - fix alignment error on sparc64 (bug 643137)
--- a/gfx/ots/include/opentype-sanitiser.h
+++ b/gfx/ots/include/opentype-sanitiser.h
@@ -17,16 +17,17 @@ typedef unsigned __int64 uint64_t;
 #include <winsock2.h>  // for htons/ntohs
 #else
 #include <arpa/inet.h>
 #include <stdint.h>
 #endif
 
 #include <algorithm>  // for std::min
 #include <cassert>
+#include <cstddef>
 #include <cstring>
 
 namespace ots {
 
 // -----------------------------------------------------------------------------
 // This is an interface for an abstract stream class which is used for writing
 // the serialised results out.
 // -----------------------------------------------------------------------------
deleted file mode 100644
--- a/gfx/ots/ots-fix-gcc46.patch
+++ /dev/null
@@ -1,18 +0,0 @@
-diff --git a/gfx/ots/src/os2.cc b/gfx/ots/src/os2.cc
---- a/gfx/ots/src/os2.cc
-+++ b/gfx/ots/src/os2.cc
-@@ -1,12 +1,14 @@
- // Copyright (c) 2009 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- 
-+#include <cstddef>
-+
- #include "os2.h"
- 
- #include "head.h"
- 
- // OS/2 - OS/2 and Windows Metrics
- // http://www.microsoft.com/opentype/otspec/os2.htm
- 
- namespace ots {
--- a/gfx/ots/src/cff.cc
+++ b/gfx/ots/src/cff.cc
@@ -184,23 +184,25 @@ bool ParseDictDataBcd(
   while (true) {
     if (!table->ReadU8(&nibble)) {
       return OTS_FAILURE();
     }
     if ((nibble & 0xf0) == 0xf0) {
       if ((nibble & 0xf) == 0xf) {
         // TODO(yusukes): would be better to store actual double value,
         // rather than the dummy integer.
-        operands->push_back(std::make_pair(0, DICT_OPERAND_REAL));
+        operands->push_back(std::make_pair(static_cast<uint32_t>(0),
+                                           DICT_OPERAND_REAL));
         return true;
       }
       return OTS_FAILURE();
     }
     if ((nibble & 0x0f) == 0x0f) {
-      operands->push_back(std::make_pair(0, DICT_OPERAND_REAL));
+      operands->push_back(std::make_pair(static_cast<uint32_t>(0),
+                                         DICT_OPERAND_REAL));
       return true;
     }
 
     // check number format
     uint8_t nibbles[2];
     nibbles[0] = (nibble & 0xf0) >> 8;
     nibbles[1] = (nibble & 0x0f);
     for (unsigned i = 0; i < 2; ++i) {
@@ -259,28 +261,30 @@ bool ParseDictDataNumber(
   uint8_t b4 = 0;
 
   switch (b0) {
     case 28:  // shortint
       if (!table->ReadU8(&b1) ||
           !table->ReadU8(&b2)) {
         return OTS_FAILURE();
       }
-      operands->push_back(std::make_pair((b1 << 8) + b2, DICT_OPERAND_INTEGER));
+      operands->push_back(std::make_pair(
+          static_cast<uint32_t>((b1 << 8) + b2), DICT_OPERAND_INTEGER));
       return true;
 
     case 29:  // longint
       if (!table->ReadU8(&b1) ||
           !table->ReadU8(&b2) ||
           !table->ReadU8(&b3) ||
           !table->ReadU8(&b4)) {
         return OTS_FAILURE();
       }
       operands->push_back(std::make_pair(
-          (b1 << 24) + (b2 << 16) + (b3 << 8) + b4, DICT_OPERAND_INTEGER));
+          static_cast<uint32_t>((b1 << 24) + (b2 << 16) + (b3 << 8) + b4),
+          DICT_OPERAND_INTEGER));
       return true;
 
     case 30:  // binary coded decimal
       return ParseDictDataBcd(table, operands);
 
     default:
       break;
   }
@@ -312,17 +316,18 @@ bool ParseDictDataReadNext(
   uint8_t op = 0;
   if (!table->ReadU8(&op)) {
     return OTS_FAILURE();
   }
   if (op <= 21) {
     if (op == 12) {
       return ParseDictDataEscapedOperator(table, operands);
     }
-    operands->push_back(std::make_pair(op, DICT_OPERATOR));
+    operands->push_back(std::make_pair(
+        static_cast<uint32_t>(op), DICT_OPERATOR));
     return true;
   } else if (op <= 27 || op == 31 || op == 255) {
     // reserved area.
     return OTS_FAILURE();
   }
 
   return ParseDictDataNumber(table, op, operands);
 }
--- a/gfx/ots/src/cmap.cc
+++ b/gfx/ots/src/cmap.cc
@@ -1,14 +1,15 @@
 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include "cmap.h"
 
+#include <algorithm>
 #include <set>
 #include <utility>
 #include <vector>
 
 #include "maxp.h"
 #include "os2.h"
 
 // cmap - Character To Glyph Index Mapping Table
@@ -689,19 +690,20 @@ bool ots_cmap_parse(OpenTypeFile *file, 
 
     if (!uniq_checker.insert(std::make_pair(subtable_headers[i].offset,
                                             end_byte)).second) {
       // Sometimes Unicode table and MS table share exactly the same data.
       // We'll allow this.
       continue;
     }
     overlap_checker.push_back(
-        std::make_pair(subtable_headers[i].offset, 1 /* start */));
+        std::make_pair(subtable_headers[i].offset,
+                       static_cast<uint8_t>(1) /* start */));
     overlap_checker.push_back(
-        std::make_pair(end_byte, 0 /* end */));
+        std::make_pair(end_byte, static_cast<uint8_t>(0) /* end */));
   }
   std::sort(overlap_checker.begin(), overlap_checker.end());
   int overlap_count = 0;
   for (unsigned i = 0; i < overlap_checker.size(); ++i) {
     overlap_count += (overlap_checker[i].second ? 1 : -1);
     if (overlap_count > 1) {
       return OTS_FAILURE();
     }
--- a/gfx/ots/src/gdef.cc
+++ b/gfx/ots/src/gdef.cc
@@ -37,17 +37,18 @@ bool ParseAttachListTable(ots::OpenTypeF
   ots::Buffer subtable(data, length);
 
   uint16_t offset_coverage = 0;
   uint16_t glyph_count = 0;
   if (!subtable.ReadU16(&offset_coverage) ||
       !subtable.ReadU16(&glyph_count)) {
     return OTS_FAILURE();
   }
-  const unsigned attach_points_end = static_cast<unsigned>(4) + 2*glyph_count;
+  const unsigned attach_points_end =
+      2 * static_cast<unsigned>(glyph_count) + 4;
   if (attach_points_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   if (offset_coverage == 0 || offset_coverage >= length ||
       offset_coverage < attach_points_end) {
     return OTS_FAILURE();
   }
   if (glyph_count > num_glyphs) {
@@ -105,17 +106,18 @@ bool ParseLigCaretListTable(ots::OpenTyp
                             size_t length, const uint16_t num_glyphs) {
   ots::Buffer subtable(data, length);
   uint16_t offset_coverage = 0;
   uint16_t lig_glyph_count = 0;
   if (!subtable.ReadU16(&offset_coverage) ||
       !subtable.ReadU16(&lig_glyph_count)) {
     return OTS_FAILURE();
   }
-  const unsigned lig_glyphs_end = static_cast<unsigned>(4) + 2*lig_glyph_count;
+  const unsigned lig_glyphs_end =
+      2 * static_cast<unsigned>(lig_glyph_count) + 4;
   if (lig_glyphs_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   if (offset_coverage == 0 || offset_coverage >= length ||
       offset_coverage < lig_glyphs_end) {
     return OTS_FAILURE();
   }
   if (lig_glyph_count > num_glyphs) {
@@ -150,17 +152,17 @@ bool ParseLigCaretListTable(ots::OpenTyp
     if (caret_count == 0) {
       OTS_WARNING("bad caret value count: %u", caret_count);
       return OTS_FAILURE();
     }
 
     std::vector<uint16_t> caret_values;
     caret_values.resize(caret_count);
     uint16_t last_offset_caret = 0;
-    unsigned caret_values_end = static_cast<unsigned>(2) + 2*caret_count;
+    unsigned caret_values_end = 2 * static_cast<unsigned>(caret_count) + 2;
     for (unsigned j = 0; j < caret_count; ++j) {
       if (!subtable.ReadU16(&caret_values[j])) {
         return OTS_FAILURE();
       }
       if (caret_values[j] >= length || caret_values[j] < caret_values_end) {
         return OTS_FAILURE();
       }
       // Caret offsets are in increasing coordinate order
@@ -210,17 +212,17 @@ bool ParseMarkGlyphSetsDefTable(ots::Ope
       !subtable.ReadU16(&mark_set_count)) {
     return OTS_FAILURE();
   }
   if (format != 1) {
     OTS_WARNING("bad mark glyph set table format: %u", format);
     return OTS_FAILURE();
   }
 
-  const unsigned mark_sets_end = static_cast<unsigned>(4) + 2*mark_set_count;
+  const unsigned mark_sets_end = 2 * static_cast<unsigned>(mark_set_count) + 4;
   if (mark_sets_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < mark_set_count; ++i) {
     uint32_t offset_coverage = 0;
     if (!subtable.ReadU32(&offset_coverage)) {
       return OTS_FAILURE();
     }
@@ -283,21 +285,19 @@ bool ots_gdef_parse(OpenTypeFile *file, 
   }
   uint16_t offset_mark_glyph_sets_def = 0;
   if (gdef->version_2) {
     if (!table.ReadU16(&offset_mark_glyph_sets_def)) {
       return OTS_FAILURE();
     }
   }
 
-  const unsigned gdef_header_end = static_cast<unsigned>(8) +
-      gdef->version_2 ? static_cast<unsigned>(2) : static_cast<unsigned>(0);
-  if (gdef_header_end > std::numeric_limits<uint16_t>::max()) {
-    return OTS_FAILURE();
-  }
+  unsigned gdef_header_end = 8;
+  if (gdef->version_2)
+    gdef_header_end += 2;
 
   // Parse subtables
   if (offset_glyph_class_def) {
     if (offset_glyph_class_def >= length ||
         offset_glyph_class_def < gdef_header_end) {
       return OTS_FAILURE();
     }
     if (!ParseGlyphClassDefTable(file, data + offset_glyph_class_def,
--- a/gfx/ots/src/glyf.cc
+++ b/gfx/ots/src/glyf.cc
@@ -106,23 +106,26 @@ bool ParseSimpleGlyph(ots::OpenTypeFile 
 
   const uint32_t gly_header_length = 10 + num_contours * 2 + 2;
   if (gly_length < (gly_header_length + bytecode_length)) {
     return OTS_FAILURE();
   }
 
   if (ots::g_transcode_hints) {
     glyf->iov.push_back(std::make_pair(
-        data + gly_offset, gly_header_length + bytecode_length));
+        data + gly_offset,
+        static_cast<size_t>(gly_header_length + bytecode_length)));
   } else {
     // enqueue two vectors: the glyph data up to the bytecode length, then
     // a pointer to a static uint16_t 0 to overwrite the length.
     glyf->iov.push_back(std::make_pair(
-        data + gly_offset, gly_header_length - 2));
-    glyf->iov.push_back(std::make_pair((const uint8_t*) "\x00\x00", 2));
+        data + gly_offset,
+        static_cast<size_t>(gly_header_length - 2)));
+    glyf->iov.push_back(std::make_pair((const uint8_t*) "\x00\x00",
+                                       static_cast<size_t>(2)));
   }
 
   if (!table->Skip(bytecode_length)) {
     return OTS_FAILURE();
   }
 
   uint32_t flags_count_physical = 0;  // on memory
   uint32_t xy_coordinates_length = 0;
@@ -148,17 +151,17 @@ bool ParseSimpleGlyph(ots::OpenTypeFile 
                     flags_count_physical + xy_coordinates_length) > 3) {
     // We allow 0-3 bytes difference since gly_length is 4-bytes aligned,
     // zero-padded length.
     return OTS_FAILURE();
   }
 
   glyf->iov.push_back(std::make_pair(
       data + gly_offset + gly_header_length + bytecode_length,
-      flags_count_physical + xy_coordinates_length));
+      static_cast<size_t>(flags_count_physical + xy_coordinates_length)));
 
   *new_size
       = gly_header_length + flags_count_physical + xy_coordinates_length;
   if (ots::g_transcode_hints) {
     *new_size += bytecode_length;
   }
 
   return true;
@@ -242,28 +245,30 @@ bool ots_glyf_parse(OpenTypeFile *file, 
     if (num_contours >= 0) {
       // this is a simple glyph and might contain bytecode
       if (!ParseSimpleGlyph(file, data, &table,
                             num_contours, gly_offset, gly_length, &new_size)) {
         return OTS_FAILURE();
       }
     } else {
       // it's a composite glyph without any bytecode. Enqueue the whole thing
-      glyf->iov.push_back(std::make_pair(data + gly_offset, gly_length));
+      glyf->iov.push_back(std::make_pair(data + gly_offset,
+                                         static_cast<size_t>(gly_length)));
       new_size = gly_length;
     }
 
     resulting_offsets[i] = current_offset;
     // glyphs must be four byte aligned
     // TODO(yusukes): investigate whether this padding is really necessary.
     //                Which part of the spec requires this?
     const unsigned padding = (4 - (new_size & 3)) % 4;
     if (padding) {
       glyf->iov.push_back(std::make_pair(
-          reinterpret_cast<const uint8_t*>("\x00\x00\x00\x00"), padding));
+          reinterpret_cast<const uint8_t*>("\x00\x00\x00\x00"),
+          static_cast<size_t>(padding)));
       new_size += padding;
     }
     current_offset += new_size;
   }
   resulting_offsets[num_glyphs] = current_offset;
 
   const uint16_t max16 = std::numeric_limits<uint16_t>::max();
   if ((*std::max_element(resulting_offsets.begin(),
--- a/gfx/ots/src/gpos.cc
+++ b/gfx/ots/src/gpos.cc
@@ -166,17 +166,17 @@ bool ParseMarkArrayTable(const uint8_t *
   ots::Buffer subtable(data, length);
 
   uint16_t mark_count = 0;
   if (!subtable.ReadU16(&mark_count)) {
     return OTS_FAILURE();
   }
 
   // MarkRecord consists of 4-bytes.
-  const unsigned mark_records_end = static_cast<unsigned>(2) + mark_count * 4;
+  const unsigned mark_records_end = 4 * static_cast<unsigned>(mark_count) + 2;
   if (mark_records_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < mark_count; ++i) {
     uint16_t class_value = 0;
     uint16_t offset_mark_anchor = 0;
     if (!subtable.ReadU16(&class_value) ||
         !subtable.ReadU16(&offset_mark_anchor)) {
@@ -284,18 +284,17 @@ bool ParsePairPosFormat1(const uint8_t *
     return OTS_FAILURE();
   }
 
   uint16_t pair_set_count = 0;
   if (!subtable.ReadU16(&pair_set_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned pair_pos_end = static_cast<unsigned>(10) +
-      pair_set_count * 2;
+  const unsigned pair_pos_end = 2 * static_cast<unsigned>(pair_set_count) + 10;
   if (pair_pos_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < pair_set_count; ++i) {
     uint16_t pair_set_offset = 0;
     if (!subtable.ReadU16(&pair_set_offset)) {
       return OTS_FAILURE();
     }
@@ -427,18 +426,18 @@ bool ParseCursiveAttachment(const ots::O
     return OTS_FAILURE();
   }
 
   if (format != 1) {
     return OTS_FAILURE();
   }
 
   // Check entry exit records.
-  const unsigned entry_exit_records_end = static_cast<unsigned>(6) +
-      entry_exit_count * 2;
+  const unsigned entry_exit_records_end =
+      2 * static_cast<unsigned>(entry_exit_count) + 6;
   if (entry_exit_records_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < entry_exit_count; ++i) {
     uint16_t offset_entry_anchor = 0;
     uint16_t offset_exit_anchor = 0;
     if (!subtable.ReadU16(&offset_entry_anchor) ||
         !subtable.ReadU16(&offset_exit_anchor)) {
@@ -483,18 +482,18 @@ bool ParseAnchorArrayTable(const uint8_t
                            const uint16_t class_count) {
   ots::Buffer subtable(data, length);
 
   uint16_t record_count = 0;
   if (!subtable.ReadU16(&record_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned anchor_array_end = static_cast<unsigned>(2) +
-      record_count * class_count * 2;
+  const unsigned anchor_array_end = 2 * static_cast<unsigned>(record_count) *
+      static_cast<unsigned>(class_count) + 2;
   if (anchor_array_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < record_count; ++i) {
     for (unsigned j = 0; j < class_count; ++j) {
       uint16_t offset_record = 0;
       if (!subtable.ReadU16(&offset_record)) {
         return OTS_FAILURE();
--- a/gfx/ots/src/gsub.cc
+++ b/gfx/ots/src/gsub.cc
@@ -387,34 +387,16 @@ bool ParseLigatureSubstitution(const ots
   if (!ots::ParseCoverageTable(data + offset_coverage,
                                length - offset_coverage, num_glyphs)) {
     return OTS_FAILURE();
   }
 
   return true;
 }
 
-bool ParseSubstLookupRecord(ots::Buffer *subtable, const uint16_t num_glyphs,
-                            const uint16_t num_lookups) {
-  uint16_t sequence_index = 0;
-  uint16_t lookup_list_index = 0;
-
-  if (!subtable->ReadU16(&sequence_index) ||
-      !subtable->ReadU16(&lookup_list_index)) {
-    return OTS_FAILURE();
-  }
-  if (sequence_index >= num_glyphs) {
-    return OTS_FAILURE();
-  }
-  if (lookup_list_index >= num_lookups) {
-    return OTS_FAILURE();
-  }
-  return true;
-}
-
 // Lookup Type 5:
 // Contextual Substitution Subtable
 bool ParseContextSubstitution(const ots::OpenTypeFile *file,
                               const uint8_t *data, const size_t length) {
   return ots::ParseContextSubtable(data, length, file->maxp->num_glyphs,
                                    file->gsub->num_lookups);
 }
 
--- a/gfx/ots/src/layout.cc
+++ b/gfx/ots/src/layout.cc
@@ -92,18 +92,18 @@ bool ParseScriptTable(const uint8_t *dat
   // The spec requires a script table for 'DFLT' tag must contain non-NULL
   // |offset_default_lang_sys| and |lang_sys_count| == 0
   if (tag == kScriptTableTagDflt &&
       (offset_default_lang_sys == 0 || lang_sys_count != 0)) {
     OTS_WARNING("DFLT table doesn't satisfy the spec.");
     return OTS_FAILURE();
   }
 
-  const unsigned lang_sys_record_end = static_cast<unsigned>(4) +
-      lang_sys_count * 6;
+  const unsigned lang_sys_record_end =
+      6 * static_cast<unsigned>(lang_sys_count) + 4;
   if (lang_sys_record_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
 
   std::vector<LangSysRecord> lang_sys_records;
   lang_sys_records.resize(lang_sys_count);
   uint32_t last_tag = 0;
   for (unsigned i = 0; i < lang_sys_count; ++i) {
@@ -141,18 +141,18 @@ bool ParseFeatureTable(const uint8_t *da
 
   uint16_t offset_feature_params = 0;
   uint16_t lookup_count = 0;
   if (!subtable.ReadU16(&offset_feature_params) ||
       !subtable.ReadU16(&lookup_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned feature_table_end = static_cast<unsigned>(4) +
-      num_lookups * 2;
+  const unsigned feature_table_end =
+      2 * static_cast<unsigned>(num_lookups) + 4;
   if (feature_table_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   // |offset_feature_params| is generally set to NULL.
   if (offset_feature_params != 0 &&
       (offset_feature_params < feature_table_end ||
        offset_feature_params >= length)) {
     return OTS_FAILURE();
@@ -205,19 +205,18 @@ bool ParseLookupTable(ots::OpenTypeFile 
     }
     use_mark_filtering_set = true;
   }
 
   std::vector<uint16_t> subtables;
   subtables.reserve(subtable_count);
   // If the |kUseMarkFilteringSetBit| of |lookup_flag| is set,
   // extra 2 bytes will follow after subtable offset array.
-  const unsigned lookup_table_end =
-      static_cast<unsigned>(use_mark_filtering_set ? 8 : 6) +
-      subtable_count * 2;
+  const unsigned lookup_table_end = 2 * static_cast<unsigned>(subtable_count) +
+      (use_mark_filtering_set ? 8 : 6);
   if (lookup_table_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < subtable_count; ++i) {
     uint16_t offset_subtable = 0;
     if (!subtable.ReadU16(&offset_subtable)) {
       return OTS_FAILURE();
     }
@@ -466,18 +465,17 @@ bool ParseRuleSetTable(const uint8_t *da
                        const uint16_t num_glyphs,
                        const uint16_t num_lookups) {
   ots::Buffer subtable(data, length);
 
   uint16_t rule_count = 0;
   if (!subtable.ReadU16(&rule_count)) {
     return OTS_FAILURE();
   }
-  const unsigned rule_end = static_cast<unsigned>(2) +
-      rule_count * 2;
+  const unsigned rule_end = 2 * static_cast<unsigned>(rule_count) + 2;
   if (rule_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
 
   for (unsigned i = 0; i < rule_count; ++i) {
     uint16_t offset_rule = 0;
     if (!subtable.ReadU16(&offset_rule)) {
       return OTS_FAILURE();
@@ -573,18 +571,18 @@ bool ParseClassSetTable(const uint8_t *d
                         const uint16_t num_glyphs,
                         const uint16_t num_lookups) {
   ots::Buffer subtable(data, length);
 
   uint16_t class_rule_count = 0;
   if (!subtable.ReadU16(&class_rule_count)) {
     return OTS_FAILURE();
   }
-  const unsigned class_rule_end = static_cast<unsigned>(2) +
-      class_rule_count * 2;
+  const unsigned class_rule_end =
+      2 * static_cast<unsigned>(class_rule_count) + 2;
   if (class_rule_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < class_rule_count; ++i) {
     uint16_t offset_class_rule = 0;
     if (!subtable.ReadU16(&offset_class_rule)) {
       return OTS_FAILURE();
     }
@@ -612,18 +610,17 @@ bool ParseContextFormat2(const uint8_t *
   // Skip format field.
   if (!subtable.Skip(2) ||
       !subtable.ReadU16(&offset_coverage) ||
       !subtable.ReadU16(&offset_class_def) ||
       !subtable.ReadU16(&class_set_cnt)) {
     return OTS_FAILURE();
   }
 
-  const unsigned class_set_end = static_cast<unsigned>(8) +
-      class_set_cnt * 2;
+  const unsigned class_set_end = 2 * static_cast<unsigned>(class_set_cnt) + 8;
   if (class_set_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   if (offset_coverage < class_set_end || offset_coverage >= length) {
     return OTS_FAILURE();
   }
   if (!ots::ParseCoverageTable(data + offset_coverage,
                                length - offset_coverage, num_glyphs)) {
@@ -671,18 +668,18 @@ bool ParseContextFormat3(const uint8_t *
       !subtable.ReadU16(&glyph_count) ||
       !subtable.ReadU16(&lookup_count)) {
     return OTS_FAILURE();
   }
 
   if (glyph_count >= num_glyphs) {
     return OTS_FAILURE();
   }
-  const unsigned lookup_record_end = static_cast<unsigned>(6) +
-      glyph_count * 2 + lookup_count * 4;
+  const unsigned lookup_record_end = 2 * static_cast<unsigned>(glyph_count) +
+      4 * static_cast<unsigned>(lookup_count) + 6;
   if (lookup_record_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < glyph_count; ++i) {
     uint16_t offset_coverage = 0;
     if (!subtable.ReadU16(&offset_coverage)) {
       return OTS_FAILURE();
     }
@@ -779,18 +776,18 @@ bool ParseChainRuleSetTable(const uint8_
                             const uint16_t num_glyphs,
                             const uint16_t num_lookups) {
   ots::Buffer subtable(data, length);
 
   uint16_t chain_rule_count = 0;
   if (!subtable.ReadU16(&chain_rule_count)) {
     return OTS_FAILURE();
   }
-  const unsigned chain_rule_end = static_cast<unsigned>(2) +
-      chain_rule_count * 2;
+  const unsigned chain_rule_end =
+      2 * static_cast<unsigned>(chain_rule_count) + 2;
   if (chain_rule_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < chain_rule_count; ++i) {
     uint16_t offset_chain_rule = 0;
     if (!subtable.ReadU16(&offset_chain_rule)) {
       return OTS_FAILURE();
     }
@@ -816,18 +813,18 @@ bool ParseChainContextFormat1(const uint
   uint16_t chain_rule_set_count = 0;
   // Skip format field.
   if (!subtable.Skip(2) ||
       !subtable.ReadU16(&offset_coverage) ||
       !subtable.ReadU16(&chain_rule_set_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned chain_rule_set_end = static_cast<unsigned>(6) +
-      chain_rule_set_count * 2;
+  const unsigned chain_rule_set_end =
+      2 * static_cast<unsigned>(chain_rule_set_count) + 6;
   if (chain_rule_set_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   if (offset_coverage < chain_rule_set_end || offset_coverage >= length) {
     return OTS_FAILURE();
   }
   if (!ots::ParseCoverageTable(data + offset_coverage,
                                length - offset_coverage, num_glyphs)) {
@@ -911,18 +908,18 @@ bool ParseChainClassSetTable(const uint8
                              const uint16_t num_glyphs,
                              const uint16_t num_lookups) {
   ots::Buffer subtable(data, length);
 
   uint16_t chain_class_rule_count = 0;
   if (!subtable.ReadU16(&chain_class_rule_count)) {
     return OTS_FAILURE();
   }
-  const unsigned chain_class_rule_end = static_cast<unsigned>(2) +
-      chain_class_rule_count * 2;
+  const unsigned chain_class_rule_end =
+      2 * static_cast<unsigned>(chain_class_rule_count) + 2;
   if (chain_class_rule_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < chain_class_rule_count; ++i) {
     uint16_t offset_chain_class_rule = 0;
     if (!subtable.ReadU16(&offset_chain_class_rule)) {
       return OTS_FAILURE();
     }
@@ -955,18 +952,18 @@ bool ParseChainContextFormat2(const uint
       !subtable.ReadU16(&offset_coverage) ||
       !subtable.ReadU16(&offset_backtrack_class_def) ||
       !subtable.ReadU16(&offset_input_class_def) ||
       !subtable.ReadU16(&offset_lookahead_class_def) ||
       !subtable.ReadU16(&chain_class_set_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned chain_class_set_end = static_cast<unsigned>(12) +
-      chain_class_set_count * 2;
+  const unsigned chain_class_set_end =
+      2 * static_cast<unsigned>(chain_class_set_count) + 12;
   if (chain_class_set_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   if (offset_coverage < chain_class_set_end || offset_coverage >= length) {
     return OTS_FAILURE();
   }
   if (!ots::ParseCoverageTable(data + offset_coverage,
                                length - offset_coverage, num_glyphs)) {
@@ -1103,18 +1100,21 @@ bool ParseChainContextFormat3(const uint
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < lookup_count; ++i) {
     if (!ParseLookupRecord(&subtable, num_glyphs, num_lookups)) {
       return OTS_FAILURE();
     }
   }
 
-  const unsigned lookup_record_end = static_cast<unsigned>(10) +
-      (backtrack_count + input_count + lookahead_count) * 2 + lookup_count * 4;
+  const unsigned lookup_record_end =
+      2 * (static_cast<unsigned>(backtrack_count) +
+           static_cast<unsigned>(input_count) +
+           static_cast<unsigned>(lookahead_count)) +
+      4 * static_cast<unsigned>(lookup_count) + 10;
   if (lookup_record_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < backtrack_count; ++i) {
     if (offsets_backtrack[i] < lookup_record_end ||
         offsets_backtrack[i] >= length) {
       return OTS_FAILURE();
     }
@@ -1170,18 +1170,18 @@ bool ParseScriptListTable(const uint8_t 
                           const uint16_t num_features) {
   Buffer subtable(data, length);
 
   uint16_t script_count = 0;
   if (!subtable.ReadU16(&script_count)) {
     return OTS_FAILURE();
   }
 
-  const unsigned script_record_end = static_cast<unsigned>(2) +
-      script_count * 6;
+  const unsigned script_record_end =
+      6 * static_cast<unsigned>(script_count) + 2;
   if (script_record_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   std::vector<ScriptRecord> script_list;
   script_list.reserve(script_count);
   uint32_t last_tag = 0;
   for (unsigned i = 0; i < script_count; ++i) {
     ScriptRecord record;
@@ -1227,18 +1227,18 @@ bool ParseFeatureListTable(const uint8_t
 
   uint16_t feature_count = 0;
   if (!subtable.ReadU16(&feature_count)) {
     return OTS_FAILURE();
   }
 
   std::vector<FeatureRecord> feature_records;
   feature_records.resize(feature_count);
-  const unsigned feature_record_end = static_cast<unsigned>(2) +
-      feature_count * 6;
+  const unsigned feature_record_end =
+      6 * static_cast<unsigned>(feature_count) + 2;
   if (feature_record_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   uint32_t last_tag = 0;
   for (unsigned i = 0; i < feature_count; ++i) {
     if (!subtable.ReadU32(&feature_records[i].tag) ||
         !subtable.ReadU16(&feature_records[i].offset)) {
       return OTS_FAILURE();
@@ -1277,18 +1277,18 @@ bool ParseLookupListTable(OpenTypeFile *
   Buffer subtable(data, length);
 
   if (!subtable.ReadU16(num_lookups)) {
     return OTS_FAILURE();
   }
 
   std::vector<uint16_t> lookups;
   lookups.reserve(*num_lookups);
-  const unsigned lookup_end = static_cast<unsigned>(2) +
-      (*num_lookups) * 2;
+  const unsigned lookup_end =
+      2 * static_cast<unsigned>(*num_lookups) + 2;
   if (lookup_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE();
   }
   for (unsigned i = 0; i < *num_lookups; ++i) {
     uint16_t offset = 0;
     if (!subtable.ReadU16(&offset)) {
       return OTS_FAILURE();
     }
--- a/gfx/ots/src/name.cc
+++ b/gfx/ots/src/name.cc
@@ -1,204 +1,210 @@
-// Copyright (c) 2011 Mozilla Foundation. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include "name.h"
 
 #include <algorithm>
 #include <cstring>
 
 #include "cff.h"
 
 // name - Naming Table
 // http://www.microsoft.com/opentype/otspec/name.htm
 
-namespace { // misc local helper functions
+namespace {
 
-inline bool
-valid_in_ps_name(char c) {
+bool ValidInPsName(char c) {
   return (c > 0x20 && c < 0x7f && !std::strchr("[](){}<>/%", c));
 }
 
-inline bool
-check_ps_name_ascii(std::string& name) {
-  for (unsigned int i = 0; i < name.size(); ++i) {
-    if (!valid_in_ps_name(name[i])) {
+bool CheckPsNameAscii(const std::string& name) {
+  for (unsigned i = 0; i < name.size(); ++i) {
+    if (!ValidInPsName(name[i])) {
       return false;
     }
   }
   return true;
 }
 
-inline bool
-check_ps_name_utf16_be(std::string& name) {
-  for (unsigned int i = 0; i < name.size(); i += 2) {
+bool CheckPsNameUtf16Be(const std::string& name) {
+  if ((name.size() & 1) != 0)
+    return false;
+
+  for (unsigned i = 0; i < name.size(); i += 2) {
     if (name[i] != 0) {
       return false;
     }
-    if (!valid_in_ps_name(name[i+1])) {
+    if (!ValidInPsName(name[i+1])) {
       return false;
     }
   }
   return true;
 }
 
-void
-assign_to_utf16_be_from_ascii(std::string& target, const std::string& source) {
-  target.resize(source.size() * 2);
-  for (unsigned int i = 0, j = 0; i < source.size(); i++) {
-    target[j++] = '\0';
-    target[j++] = source[i];
+void AssignToUtf16BeFromAscii(std::string* target,
+                              const std::string& source) {
+  target->resize(source.size() * 2);
+  for (unsigned i = 0, j = 0; i < source.size(); i++) {
+    (*target)[j++] = '\0';
+    (*target)[j++] = source[i];
   }
 }
 
-} // end anonymous namespace
+}  // namespace
+
 
 namespace ots {
 
-bool ots_name_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
+bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) {
   Buffer table(data, length);
 
-  OpenTypeNAME *name = new OpenTypeNAME;
+  OpenTypeNAME* name = new OpenTypeNAME;
   file->name = name;
 
-  uint16_t format;
+  uint16_t format = 0;
   if (!table.ReadU16(&format) || format > 1) {
     return OTS_FAILURE();
   }
 
-  uint16_t count;
+  uint16_t count = 0;
   if (!table.ReadU16(&count)) {
     return OTS_FAILURE();
   }
 
-  uint16_t stringOffset;
-  if (!table.ReadU16(&stringOffset) || stringOffset > length) {
+  uint16_t string_offset = 0;
+  if (!table.ReadU16(&string_offset) || string_offset > length) {
     return OTS_FAILURE();
   }
-  const char* stringBase = (const char*)data + stringOffset;
+  const char* string_base = reinterpret_cast<const char*>(data) +
+      string_offset;
 
-  NameRecord prevRec;
-  bool sortRequired = false;
+  NameRecord prev_record;
+  bool sort_required = false;
 
   // Read all the names, discarding any with invalid IDs,
   // and any where the offset/length would be outside the table.
   // A stricter alternative would be to reject the font if there
   // are invalid name records, but it's not clear that is necessary.
-  for (unsigned int i = 0; i < count; ++i) {
+  for (unsigned i = 0; i < count; ++i) {
     NameRecord rec;
-    uint16_t nameLength, nameOffset;
-    if (!table.ReadU16(&rec.platformID) ||
-        !table.ReadU16(&rec.encodingID) ||
-        !table.ReadU16(&rec.languageID) ||
-        !table.ReadU16(&rec.nameID) ||
-        !table.ReadU16(&nameLength) ||
-        !table.ReadU16(&nameOffset)) {
+    uint16_t name_length, name_offset;
+    if (!table.ReadU16(&rec.platform_id) ||
+        !table.ReadU16(&rec.encoding_id) ||
+        !table.ReadU16(&rec.language_id) ||
+        !table.ReadU16(&rec.name_id) ||
+        !table.ReadU16(&name_length) ||
+        !table.ReadU16(&name_offset)) {
       return OTS_FAILURE();
     }
     // check platform & encoding, discard names with unknown values
-    switch (rec.platformID) {
-    case 0: // Unicode
-      if (rec.encodingID > 6) {
-        continue;
-      }
-      break;
-    case 1: // Macintosh
-      if (rec.encodingID > 32) {
-        continue;
-      }
-      break;
-    case 2: // ISO
-      if (rec.encodingID > 2) {
+    switch (rec.platform_id) {
+      case 0:  // Unicode
+        if (rec.encoding_id > 6) {
+          continue;
+        }
+        break;
+      case 1:  // Macintosh
+        if (rec.encoding_id > 32) {
+          continue;
+        }
+        break;
+      case 2:  // ISO
+        if (rec.encoding_id > 2) {
+          continue;
+        }
+        break;
+      case 3:  // Windows: IDs 7 to 9 are "reserved"
+        if (rec.encoding_id > 6 && rec.encoding_id != 10) {
+          continue;
+        }
+        break;
+      case 4:  // Custom (OTF Windows NT compatibility)
+        if (rec.encoding_id > 255) {
+          continue;
+        }
+        break;
+      default:  // unknown platform
         continue;
-      }
-      break;
-    case 3: // Windows: IDs 7 to 9 are "reserved"
-      if (rec.encodingID > 6 && rec.encodingID != 10) {
-        continue;
-      }
-      break;
-    case 4: // Custom (OTF Windows NT compatibility)
-      if (rec.encodingID > 255) {
-        continue;
-      }
-      break;
-    default: // unknown platform
+    }
+
+    const unsigned name_end = static_cast<unsigned>(string_offset) +
+        name_offset + name_length;
+    if (name_end > length) {
       continue;
     }
+    rec.text.resize(name_length);
+    rec.text.assign(string_base + name_offset, name_length);
 
-    if (size_t(stringOffset) + nameOffset + nameLength > length) {
-      continue;
-    }
-    rec.text.resize(nameLength);
-    rec.text.assign(stringBase + nameOffset, nameLength);
-
-    if (rec.nameID == 6) {
+    if (rec.name_id == 6) {
       // PostScript name: check that it is valid, if not then discard it
-      if (rec.platformID == 1) {
+      if (rec.platform_id == 1) {
         if (file->cff && !file->cff->name.empty()) {
           rec.text = file->cff->name;
-        } else if (!check_ps_name_ascii(rec.text)) {
+        } else if (!CheckPsNameAscii(rec.text)) {
           continue;
         }
-      } else if (rec.platformID == 0 || rec.platformID == 3) {
+      } else if (rec.platform_id == 0 || rec.platform_id == 3) {
         if (file->cff && !file->cff->name.empty()) {
-          assign_to_utf16_be_from_ascii(rec.text, file->cff->name);
-        } else if (!check_ps_name_utf16_be(rec.text)) {
+          AssignToUtf16BeFromAscii(&rec.text, file->cff->name);
+        } else if (!CheckPsNameUtf16Be(rec.text)) {
           continue;
         }
       }
     }
 
-    if (i > 0) {
-      if (!(prevRec < rec)) {
-        sortRequired = true;
-      }
+    if ((i > 0) && !(prev_record < rec)) {
+      OTS_WARNING("name records are not sorted.");
+      sort_required = true;
     }
 
     name->names.push_back(rec);
-    prevRec = rec;
+    prev_record = rec;
   }
 
   if (format == 1) {
     // extended name table format with language tags
-    uint16_t langTagCount;
-    if (!table.ReadU16(&langTagCount)) {
+    uint16_t lang_tag_count;
+    if (!table.ReadU16(&lang_tag_count)) {
       return OTS_FAILURE();
     }
-    for (unsigned int i = 0; i < langTagCount; ++i) {
-      uint16_t tagLength, tagOffset;
-      if (!table.ReadU16(&tagLength) || !table.ReadU16(&tagOffset)) {
+    for (unsigned i = 0; i < lang_tag_count; ++i) {
+      uint16_t tag_length = 0;
+      uint16_t tag_offset = 0;
+      if (!table.ReadU16(&tag_length) || !table.ReadU16(&tag_offset)) {
         return OTS_FAILURE();
       }
-      if (size_t(stringOffset) + tagOffset + tagLength > length) {
+      const unsigned tag_end = static_cast<unsigned>(string_offset) +
+          tag_offset + tag_length;
+      if (tag_end > length) {
         return OTS_FAILURE();
       }
-      std::string tag(stringBase + tagOffset, tagLength);
-      name->langTags.push_back(tag);
+      std::string tag(string_base + tag_offset, tag_length);
+      name->lang_tags.push_back(tag);
     }
   }
 
-  if (table.offset() > stringOffset) {
+  if (table.offset() > string_offset) {
     // the string storage apparently overlapped the name/tag records;
     // consider this font to be badly broken
     return OTS_FAILURE();
   }
 
   // check existence of required name strings (synthesize if necessary)
   //  [0 - copyright - skip]
   //   1 - family
   //   2 - subfamily
   //  [3 - unique ID - skip]
   //   4 - full name
   //   5 - version
   //   6 - postscript name
-  const unsigned int kStdNameCount = 7;
-  const char* kStdNames[kStdNameCount] = {
+  static const unsigned kStdNameCount = 7;
+  static const char* kStdNames[kStdNameCount] = {
     NULL,
     "OTS derived font",
     "Unspecified",
     NULL,
     "OTS derived font",
     "1.000",
     "OTS-derived-font"
   };
@@ -206,118 +212,121 @@ bool ots_name_parse(OpenTypeFile *file, 
   // translated to ASCII, must also be identical to the font name as stored in
   // the CFF's Name INDEX." And actually, Mac OS X's font parser requires that.
   if (file->cff && !file->cff->name.empty()) {
     kStdNames[6] = file->cff->name.c_str();
   }
 
   // scan the names to check whether the required "standard" ones are present;
   // if not, we'll add our fixed versions here
-  bool macName[kStdNameCount] = { 0 };
-  bool winName[kStdNameCount] = { 0 };
-  for (std::vector<NameRecord>::iterator nameIter = name->names.begin();
-       nameIter != name->names.end(); nameIter++) {
-    uint16_t id = nameIter->nameID;
+  bool mac_name[kStdNameCount] = { 0 };
+  bool win_name[kStdNameCount] = { 0 };
+  for (std::vector<NameRecord>::iterator name_iter = name->names.begin();
+       name_iter != name->names.end(); name_iter++) {
+    const uint16_t id = name_iter->name_id;
     if (id >= kStdNameCount || kStdNames[id] == NULL) {
       continue;
     }
-    if (nameIter->platformID == 1) {
-      macName[id] = true;
+    if (name_iter->platform_id == 1) {
+      mac_name[id] = true;
       continue;
     }
-    if (nameIter->platformID == 3) {
-      winName[id] = true;
+    if (name_iter->platform_id == 3) {
+      win_name[id] = true;
       continue;
     }
   }
 
-  for (unsigned int i = 0; i < kStdNameCount; ++i) {
+  for (unsigned i = 0; i < kStdNameCount; ++i) {
     if (kStdNames[i] == NULL) {
       continue;
     }
-    if (!macName[i]) {
-      NameRecord rec(1, 0, 0, i);
+    if (!mac_name[i]) {
+      NameRecord rec(1 /* platform_id */, 0 /* encoding_id */,
+                     0 /* language_id */ , i /* name_id */);
       rec.text.assign(kStdNames[i]);
       name->names.push_back(rec);
-      sortRequired = true;
+      sort_required = true;
     }
-    if (!winName[i]) {
-      NameRecord rec(3, 1, 1033, i);
-      assign_to_utf16_be_from_ascii(rec.text, std::string(kStdNames[i]));
+    if (!win_name[i]) {
+      NameRecord rec(3 /* platform_id */, 1 /* encoding_id */,
+                     1033 /* language_id */ , i /* name_id */);
+      AssignToUtf16BeFromAscii(&rec.text, std::string(kStdNames[i]));
       name->names.push_back(rec);
-      sortRequired = true;
+      sort_required = true;
     }
   }
 
-  if (sortRequired) {
+  if (sort_required) {
     std::sort(name->names.begin(), name->names.end());
   }
 
   return true;
 }
 
-bool ots_name_should_serialise(OpenTypeFile *file) {
+bool ots_name_should_serialise(OpenTypeFile* file) {
   return file->name != NULL;
 }
 
-bool ots_name_serialise(OTSStream *out, OpenTypeFile *file) {
-  const OpenTypeNAME *name = file->name;
+bool ots_name_serialise(OTSStream* out, OpenTypeFile* file) {
+  const OpenTypeNAME* name = file->name;
 
-  uint16_t nameCount = name->names.size();
-  uint16_t langTagCount = name->langTags.size();
+  uint16_t name_count = name->names.size();
+  uint16_t lang_tag_count = name->lang_tags.size();
   uint16_t format = 0;
-  size_t stringOffset = 6 + nameCount * 12;
+  size_t string_offset = 6 + name_count * 12;
 
-  if (name->langTags.size() > 0) {
+  if (name->lang_tags.size() > 0) {
     // lang tags require a format-1 name table
     format = 1;
-    stringOffset = 8 + nameCount * 12 + langTagCount * 4;
+    string_offset += 2 + lang_tag_count * 4;
   }
-  if (stringOffset > 0xffff) {
+  if (string_offset > 0xffff) {
     return OTS_FAILURE();
   }
   if (!out->WriteU16(format) ||
-      !out->WriteU16(nameCount) ||
-      !out->WriteU16(stringOffset)) {
+      !out->WriteU16(name_count) ||
+      !out->WriteU16(string_offset)) {
     return OTS_FAILURE();
   }
 
-  std::string stringData;
-  for (std::vector<NameRecord>::const_iterator nameIter = name->names.begin();
-       nameIter != name->names.end(); nameIter++) {
-    const NameRecord& rec = *nameIter;
-    if (!out->WriteU16(rec.platformID) ||
-        !out->WriteU16(rec.encodingID) ||
-        !out->WriteU16(rec.languageID) ||
-        !out->WriteU16(rec.nameID) ||
+  std::string string_data;
+  for (std::vector<NameRecord>::const_iterator name_iter = name->names.begin();
+       name_iter != name->names.end(); name_iter++) {
+    const NameRecord& rec = *name_iter;
+    if (!out->WriteU16(rec.platform_id) ||
+        !out->WriteU16(rec.encoding_id) ||
+        !out->WriteU16(rec.language_id) ||
+        !out->WriteU16(rec.name_id) ||
         !out->WriteU16(rec.text.size()) ||
-        !out->WriteU16(stringData.size()) ) {
+        !out->WriteU16(string_data.size()) ) {
       return OTS_FAILURE();
     }
-    stringData.append(rec.text);
+    string_data.append(rec.text);
   }
 
   if (format == 1) {
-    if (!out->WriteU16(langTagCount)) {
+    if (!out->WriteU16(lang_tag_count)) {
       return OTS_FAILURE();
     }
-    for (std::vector<std::string>::const_iterator tagIter = name->langTags.begin();
-         tagIter != name->langTags.end(); tagIter++) {
-      if (!out->WriteU16(tagIter->size()) ||
-          !out->WriteU16(stringData.size())) {
+    for (std::vector<std::string>::const_iterator tag_iter =
+             name->lang_tags.begin();
+         tag_iter != name->lang_tags.end(); tag_iter++) {
+      if (!out->WriteU16(tag_iter->size()) ||
+          !out->WriteU16(string_data.size())) {
         return OTS_FAILURE();
       }
-      stringData.append(*tagIter);
+      string_data.append(*tag_iter);
     }
   }
 
-  if (!out->Write(stringData.data(), stringData.size())) {
+  if (!out->Write(string_data.data(), string_data.size())) {
     return OTS_FAILURE();
   }
 
   return true;
 }
 
-void ots_name_free(OpenTypeFile *file) {
+void ots_name_free(OpenTypeFile* file) {
   delete file->name;
 }
 
 }  // namespace
--- a/gfx/ots/src/name.h
+++ b/gfx/ots/src/name.h
@@ -1,50 +1,53 @@
-// Copyright (c) 2011 Mozilla Foundation. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #ifndef OTS_NAME_H_
 #define OTS_NAME_H_
 
 #include <new>
+#include <string>
 #include <utility>
 #include <vector>
-#include <string>
 
 #include "ots.h"
 
 namespace ots {
 
 struct NameRecord {
-  NameRecord()
-  { }
+  NameRecord() {
+  }
 
-  NameRecord(uint16_t p, uint16_t e, uint16_t l, uint16_t n)
-    : platformID(p), encodingID(e), languageID(l), nameID(n)
-  { }
+  NameRecord(uint16_t platform_id, uint16_t encoding_id,
+             uint16_t language_id, uint16_t name_id)
+    : platform_id(platform_id),
+      encoding_id(encoding_id),
+      language_id(language_id),
+      name_id(name_id) {
+  }
 
-  uint16_t platformID;
-  uint16_t encodingID;
-  uint16_t languageID;
-  uint16_t nameID;
+  uint16_t platform_id;
+  uint16_t encoding_id;
+  uint16_t language_id;
+  uint16_t name_id;
   std::string text;
 
   bool operator<(const NameRecord& rhs) const {
-    if (platformID < rhs.platformID) return true;
-    if (platformID > rhs.platformID) return false;
-    if (encodingID < rhs.encodingID) return true;
-    if (encodingID > rhs.encodingID) return false;
-    if (languageID < rhs.languageID) return true;
-    if (languageID > rhs.languageID) return false;
-    if (nameID < rhs.nameID) return true;
-    return false;
+    if (platform_id < rhs.platform_id) return true;
+    if (platform_id > rhs.platform_id) return false;
+    if (encoding_id < rhs.encoding_id) return true;
+    if (encoding_id > rhs.encoding_id) return false;
+    if (language_id < rhs.language_id) return true;
+    if (language_id > rhs.language_id) return false;
+    return name_id < rhs.name_id;
   }
 };
 
 struct OpenTypeNAME {
-  std::vector<NameRecord>  names;
-  std::vector<std::string> langTags;
+  std::vector<NameRecord> names;
+  std::vector<std::string> lang_tags;
 };
 
 }  // namespace ots
 
 #endif  // OTS_NAME_H_
--- a/gfx/ots/src/os2.cc
+++ b/gfx/ots/src/os2.cc
@@ -1,14 +1,12 @@
 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include <cstddef>
-
 #include "os2.h"
 
 #include "head.h"
 
 // OS/2 - OS/2 and Windows Metrics
 // http://www.microsoft.com/opentype/otspec/os2.htm
 
 namespace ots {
--- a/gfx/ots/src/ots.cc
+++ b/gfx/ots/src/ots.cc
@@ -387,19 +387,20 @@ bool ProcessGeneric(ots::OpenTypeFile *h
   for (unsigned i = 0; i < header->num_tables; ++i) {
     table_map[tables[i].tag] = tables[i];
   }
 
   // check that the tables are not overlapping.
   std::vector<std::pair<uint32_t, uint8_t> > overlap_checker;
   for (unsigned i = 0; i < header->num_tables; ++i) {
     overlap_checker.push_back(
-        std::make_pair(tables[i].offset, 1 /* start */));
+        std::make_pair(tables[i].offset, static_cast<uint8_t>(1) /* start */));
     overlap_checker.push_back(
-        std::make_pair(tables[i].offset + tables[i].length, 0 /* end */));
+        std::make_pair(tables[i].offset + tables[i].length,
+                       static_cast<uint8_t>(0) /* end */));
   }
   std::sort(overlap_checker.begin(), overlap_checker.end());
   int overlap_count = 0;
   for (unsigned i = 0; i < overlap_checker.size(); ++i) {
     overlap_count += (overlap_checker[i].second ? 1 : -1);
     if (overlap_count > 1) {
       return OTS_FAILURE();
     }
--- a/gfx/ots/src/ots.h
+++ b/gfx/ots/src/ots.h
@@ -1,16 +1,18 @@
 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #ifndef OTS_H_
 #define OTS_H_
 
+#include <stddef.h>
 #include <cstdarg>
+#include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 
 #include "opentype-sanitiser.h"
 
 namespace ots {