Skip to content

Commit

Permalink
Fix crash on Windows caused by fonts with bad name tables #7
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 2, 2016
1 parent 947b17e commit ba3289d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/FontManagerWindows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unsigned int getLocaleIndex(IDWriteLocalizedStrings *strings) {

// gets a localized string for a font
char *getString(IDWriteFont *font, DWRITE_INFORMATIONAL_STRING_ID string_id) {
char *res = "";
char *res = NULL;
IDWriteLocalizedStrings *strings = NULL;

BOOL exists = false;
Expand All @@ -59,9 +59,8 @@ char *getString(IDWriteFont *font, DWRITE_INFORMATIONAL_STRING_ID string_id) {
&exists
));

unsigned int index = getLocaleIndex(strings);

if (exists) {
unsigned int index = getLocaleIndex(strings);
unsigned int len = 0;
WCHAR *str = NULL;

Expand All @@ -73,9 +72,15 @@ char *getString(IDWriteFont *font, DWRITE_INFORMATIONAL_STRING_ID string_id) {
// convert to utf8
res = utf16ToUtf8(str);
delete str;

strings->Release();
}

strings->Release();

if (!res) {
res = new char[1];
res[0] = '\0';
}

return res;
}

Expand Down

0 comments on commit ba3289d

Please sign in to comment.