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

Side by Side Diff: src/cff_type2_charstring.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/cff.cc ('k') | src/cmap.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // A parser for the Type 2 Charstring Format. 5 // A parser for the Type 2 Charstring Format.
6 // http://www.adobe.com/devnet/font/pdfs/5177.Type2.pdf 6 // http://www.adobe.com/devnet/font/pdfs/5177.Type2.pdf
7 7
8 #include "cff_type2_charstring.h" 8 #include "cff_type2_charstring.h"
9 9
10 #include <climits> 10 #include <climits>
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 723
724 namespace ots { 724 namespace ots {
725 725
726 bool ValidateType2CharStringIndex( 726 bool ValidateType2CharStringIndex(
727 const CFFIndex& char_strings_index, 727 const CFFIndex& char_strings_index,
728 const CFFIndex& global_subrs_index, 728 const CFFIndex& global_subrs_index,
729 const std::map<uint16_t, uint8_t> &fd_select, 729 const std::map<uint16_t, uint8_t> &fd_select,
730 const std::vector<CFFIndex *> &local_subrs_per_font, 730 const std::vector<CFFIndex *> &local_subrs_per_font,
731 const CFFIndex *local_subrs, 731 const CFFIndex *local_subrs,
732 Buffer* cff_table) { 732 Buffer* cff_table) {
733 if (char_strings_index.offsets.size() == 0) { 733 const uint16_t num_offsets =
734 static_cast<uint16_t>(char_strings_index.offsets.size());
735 if (num_offsets != char_strings_index.offsets.size() || num_offsets == 0) {
734 return OTS_FAILURE(); // no charstring. 736 return OTS_FAILURE(); // no charstring.
735 } 737 }
736 738
737 // For each glyph, validate the corresponding charstring. 739 // For each glyph, validate the corresponding charstring.
738 for (unsigned i = 1; i < char_strings_index.offsets.size(); ++i) { 740 for (uint16_t i = 1; i < num_offsets; ++i) {
739 // Prepare a Buffer object, |char_string|, which contains the charstring 741 // Prepare a Buffer object, |char_string|, which contains the charstring
740 // for the |i|-th glyph. 742 // for the |i|-th glyph.
741 const size_t length = 743 const size_t length =
742 char_strings_index.offsets[i] - char_strings_index.offsets[i - 1]; 744 char_strings_index.offsets[i] - char_strings_index.offsets[i - 1];
743 if (length > kMaxCharStringLength) { 745 if (length > kMaxCharStringLength) {
744 return OTS_FAILURE(); 746 return OTS_FAILURE();
745 } 747 }
746 const size_t offset = char_strings_index.offsets[i - 1]; 748 const size_t offset = char_strings_index.offsets[i - 1];
747 cff_table->set_offset(offset); 749 cff_table->set_offset(offset);
748 if (!cff_table->Skip(length)) { 750 if (!cff_table->Skip(length)) {
749 return OTS_FAILURE(); 751 return OTS_FAILURE();
750 } 752 }
751 Buffer char_string(cff_table->buffer() + offset, length); 753 Buffer char_string(cff_table->buffer() + offset, length);
752 754
753 // Get a local subrs for the glyph. 755 // Get a local subrs for the glyph.
754 const unsigned glyph_index = i - 1; // index in the map is 0-origin. 756 const uint16_t glyph_index = i - 1; // index in the map is 0-origin.
755 const CFFIndex *local_subrs_to_use = NULL; 757 const CFFIndex *local_subrs_to_use = NULL;
756 if (!SelectLocalSubr(fd_select, 758 if (!SelectLocalSubr(fd_select,
757 local_subrs_per_font, 759 local_subrs_per_font,
758 local_subrs, 760 local_subrs,
759 glyph_index, 761 glyph_index,
760 &local_subrs_to_use)) { 762 &local_subrs_to_use)) {
761 return OTS_FAILURE(); 763 return OTS_FAILURE();
762 } 764 }
763 // If |local_subrs_to_use| is still NULL, use an empty one. 765 // If |local_subrs_to_use| is still NULL, use an empty one.
764 CFFIndex default_empty_subrs; 766 CFFIndex default_empty_subrs;
(...skipping 13 matching lines...) Expand all
778 return OTS_FAILURE(); 780 return OTS_FAILURE();
779 } 781 }
780 if (!found_endchar) { 782 if (!found_endchar) {
781 return OTS_FAILURE(); 783 return OTS_FAILURE();
782 } 784 }
783 } 785 }
784 return true; 786 return true;
785 } 787 }
786 788
787 } // namespace ots 789 } // namespace ots
OLDNEW
« no previous file with comments | « src/cff.cc ('k') | src/cmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698