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

Side by Side Diff: src/ports/SkFontConfigParser_android.cpp

Issue 226183002: Prevent potential leaking of memory by using SkString and SkTArray. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkTDArray.h" 9 #include "SkTDArray.h"
10 #include "SkTypeface.h" 10 #include "SkTypeface.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 /** 46 /**
47 * Handler for arbitrary text. This is used to parse the text inside each name 47 * Handler for arbitrary text. This is used to parse the text inside each name
48 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays. 48 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays.
49 */ 49 */
50 static void textHandler(void *data, const char *s, int len) { 50 static void textHandler(void *data, const char *s, int len) {
51 FamilyData *familyData = (FamilyData*) data; 51 FamilyData *familyData = (FamilyData*) data;
52 // Make sure we're in the right state to store this name information 52 // Make sure we're in the right state to store this name information
53 if (familyData->currentFamily && 53 if (familyData->currentFamily &&
54 (familyData->currentTag == NAMESET_TAG || familyData->currentTag == FILESET_TAG)) { 54 (familyData->currentTag == NAMESET_TAG || familyData->currentTag == FILESET_TAG)) {
55 // Malloc new buffer to store the string
56 char *buff;
57 buff = (char*) malloc((len + 1) * sizeof(char));
58 strncpy(buff, s, len);
59 buff[len] = '\0';
60 switch (familyData->currentTag) { 55 switch (familyData->currentTag) {
61 case NAMESET_TAG: 56 case NAMESET_TAG:
62 *(familyData->currentFamily->fNames.append()) = buff; 57 familyData->currentFamily->fNames.push_back().set(s, len);
63 break; 58 break;
64 case FILESET_TAG: 59 case FILESET_TAG:
65 if (familyData->currentFontInfo) { 60 if (familyData->currentFontInfo) {
66 familyData->currentFontInfo->fFileName = buff; 61 familyData->currentFontInfo->fFileName.set(s, len);
67 } 62 }
68 break; 63 break;
69 default: 64 default:
70 // Noop - don't care about any text that's not in the Fonts or Names list 65 // Noop - don't care about any text that's not in the Fonts or Names list
71 break; 66 break;
72 } 67 }
73 } 68 }
74 } 69 }
75 70
76 /** 71 /**
77 * Handler for font files. This processes the attributes for language and 72 * Handler for font files. This processes the attributes for language and
78 * variants then lets textHandler handle the actual file name 73 * variants then lets textHandler handle the actual file name
79 */ 74 */
80 static void fontFileElementHandler(FamilyData *familyData, const char **attribut es) { 75 static void fontFileElementHandler(FamilyData *familyData, const char **attribut es) {
81 FontFileInfo* newFileInfo = new FontFileInfo(); 76
77 FontFileInfo& newFileInfo = familyData->currentFamily->fFontFiles.push_back( );
82 if (attributes) { 78 if (attributes) {
83 int currentAttributeIndex = 0; 79 int currentAttributeIndex = 0;
84 while (attributes[currentAttributeIndex]) { 80 while (attributes[currentAttributeIndex]) {
85 const char* attributeName = attributes[currentAttributeIndex]; 81 const char* attributeName = attributes[currentAttributeIndex];
86 const char* attributeValue = attributes[currentAttributeIndex+1]; 82 const char* attributeValue = attributes[currentAttributeIndex+1];
87 int nameLength = strlen(attributeName); 83 int nameLength = strlen(attributeName);
88 int valueLength = strlen(attributeValue); 84 int valueLength = strlen(attributeValue);
89 if (strncmp(attributeName, "variant", nameLength) == 0) { 85 if (strncmp(attributeName, "variant", nameLength) == 0) {
90 if (strncmp(attributeValue, "elegant", valueLength) == 0) { 86 if (strncmp(attributeValue, "elegant", valueLength) == 0) {
91 newFileInfo->fPaintOptions.setFontVariant(SkPaintOptionsAndr oid::kElegant_Variant); 87 newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndro id::kElegant_Variant);
92 } else if (strncmp(attributeValue, "compact", valueLength) == 0) { 88 } else if (strncmp(attributeValue, "compact", valueLength) == 0) {
93 newFileInfo->fPaintOptions.setFontVariant(SkPaintOptionsAndr oid::kCompact_Variant); 89 newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndro id::kCompact_Variant);
94 } 90 }
95 } else if (strncmp(attributeName, "lang", nameLength) == 0) { 91 } else if (strncmp(attributeName, "lang", nameLength) == 0) {
96 newFileInfo->fPaintOptions.setLanguage(attributeValue); 92 newFileInfo.fPaintOptions.setLanguage(attributeValue);
97 } 93 }
98 //each element is a pair of attributeName/attributeValue string pair s 94 //each element is a pair of attributeName/attributeValue string pair s
99 currentAttributeIndex += 2; 95 currentAttributeIndex += 2;
100 } 96 }
101 } 97 }
102 *(familyData->currentFamily->fFontFiles.append()) = newFileInfo; 98 familyData->currentFontInfo = &newFileInfo;
103 familyData->currentFontInfo = newFileInfo;
104 XML_SetCharacterDataHandler(*familyData->parser, textHandler); 99 XML_SetCharacterDataHandler(*familyData->parser, textHandler);
105 } 100 }
106 101
107 /** 102 /**
108 * Handler for the start of a tag. The only tags we expect are family, nameset, 103 * Handler for the start of a tag. The only tags we expect are family, nameset,
109 * fileset, name, and file. 104 * fileset, name, and file.
110 */ 105 */
111 static void startElementHandler(void *data, const char *tag, const char **atts) { 106 static void startElementHandler(void *data, const char *tag, const char **atts) {
112 FamilyData *familyData = (FamilyData*) data; 107 FamilyData *familyData = (FamilyData*) data;
113 int len = strlen(tag); 108 int len = strlen(tag);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 SkString locale(6); 306 SkString locale(6);
312 char* localeCStr = locale.writable_str(); 307 char* localeCStr = locale.writable_str();
313 308
314 strncpy(localeCStr, propLang, 2); 309 strncpy(localeCStr, propLang, 2);
315 localeCStr[2] = '-'; 310 localeCStr[2] = '-';
316 strncpy(&localeCStr[3], propRegn, 2); 311 strncpy(&localeCStr[3], propRegn, 2);
317 localeCStr[5] = '\0'; 312 localeCStr[5] = '\0';
318 313
319 return locale; 314 return locale;
320 } 315 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698