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

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 1125413003: Trim whitespace from parsed filename in Android v21. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Avoid possible use after free. Created 5 years, 7 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 | « resources/android_fonts/v22/fonts.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index e60f4e4ea307a3e74e58495c4ca6f80be0f2b668..d1bcec2c7b0256aa4a95e8e39922b80f2f154eff 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -263,6 +263,19 @@ static void XMLCALL start_element_handler(void* data, const char* tag, const cha
}
}
+static void trim_string(SkString* s) {
+ char* str = s->writable_str();
+ const char* start = str;
+ const char* end = start + s->size();
+ for (; *start == ' ' || *start == '\n'|| *start == '\r' || *start == '\t'; ++start) { }
djsollen 2015/05/08 13:56:13 while I can appreciate the compactness of this it
bungeman-skia 2015/05/08 15:05:04 Done.
+ if (start != end) {
+ for (--end; *end == ' ' || *end == '\n'|| *end == '\r' || *end == '\t'; --end) { }
djsollen 2015/05/08 13:56:13 comment why you need the --end at the begin and en
bungeman-skia 2015/05/08 15:05:04 Done.
+ ++end;
+ }
+ memmove(str, start, end - start);
+ s->resize(end - start);
+}
+
static void XMLCALL end_element_handler(void* data, const char* tag) {
FamilyData* self = static_cast<FamilyData*>(data);
size_t len = strlen(tag);
@@ -270,6 +283,7 @@ static void XMLCALL end_element_handler(void* data, const char* tag) {
*self->fFamilies.append() = self->fCurrentFamily.detach();
} else if (MEMEQ("font", tag, len)) {
XML_SetCharacterDataHandler(self->fParser, NULL);
+ trim_string(&self->fCurrentFontInfo->fFileName);
}
}
« no previous file with comments | « resources/android_fonts/v22/fonts.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698