[Fontconfig] fontconfig: Branch 'master' - 3 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Thu Aug 13 15:22:04 PDT 2009
src/fcxml.c | 55 +++++++++++++++++++++----------------------------------
1 file changed, 21 insertions(+), 34 deletions(-)
New commits:
commit 8b1ceef0b7f41703775c163d6ac595a5407e9159
Author: Tor Lillqvist <tml at iki.fi>
Date: Fri Aug 14 00:16:18 2009 +0300
Use multi-byte codepage aware string function on Windows
The East Asian double-byte codepages have characters with backslash as
the second byte, so we must use _mbsrchr() instead of strrchr() when
looking at pathnames in the system codepage.
diff --git a/src/fcxml.c b/src/fcxml.c
index e829422..ef85a4f 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -57,6 +57,7 @@
#define STRICT
#include <windows.h>
#undef STRICT
+#include <mbstring.h>
#endif
static void
@@ -2059,7 +2060,13 @@ FcEndElement(void *userData, const XML_Char *name)
FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
break;
}
- p = strrchr (data, '\\');
+ /*
+ * Must use the multi-byte aware function to search
+ * for backslash because East Asian double-byte code
+ * pages have characters with backslash as the second
+ * byte.
+ */
+ p = _mbsrchr (data, '\\');
if (p) *p = '\0';
strcat (data, "\\fonts");
}
@@ -2072,7 +2079,7 @@ FcEndElement(void *userData, const XML_Char *name)
FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
break;
}
- p = strrchr (data, '\\');
+ p = _mbsrchr (data, '\\');
if (p) *p = '\0';
strcat (data, "\\..\\share\\fonts");
}
commit d15678127aeea96c9c8254a171c2f0af0bd7d140
Author: Tor Lillqvist <tml at iki.fi>
Date: Fri Aug 14 00:08:17 2009 +0300
Fix heap corruption on Windows in FcEndElement()
Must not call FcStrFree() on a value returned by
FcStrBufDoneStatic(). In the Windows code don't bother with dynamic
allocation, just use a local buffer.
diff --git a/src/fcxml.c b/src/fcxml.c
index 7b7bbfd..e829422 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -2031,7 +2031,10 @@ FcEndElement(void *userData, const XML_Char *name)
{
FcConfigParse *parse = userData;
FcChar8 *data;
-
+#ifdef _WIN32
+ FcChar8 buffer[1000];
+#endif
+
if (!parse->pstack)
return;
switch (parse->pstack->element) {
@@ -2050,18 +2053,10 @@ FcEndElement(void *userData, const XML_Char *name)
if (strcmp (data, "CUSTOMFONTDIR") == 0)
{
char *p;
- FcStrFree (data);
- data = malloc (1000);
- if (!data)
- {
- FcConfigMessage (parse, FcSevereError, "out of memory");
- break;
- }
- FcMemAlloc (FC_MEM_STRING, 1000);
- if(!GetModuleFileName(NULL, data, 1000))
+ data = buffer;
+ if (!GetModuleFileName (NULL, buffer, sizeof (buffer) - 20))
{
FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
- FcStrFree (data);
break;
}
p = strrchr (data, '\\');
@@ -2071,18 +2066,10 @@ FcEndElement(void *userData, const XML_Char *name)
else if (strcmp (data, "APPSHAREFONTDIR") == 0)
{
char *p;
- FcStrFree (data);
- data = malloc (1000);
- if (!data)
- {
- FcConfigMessage (parse, FcSevereError, "out of memory");
- break;
- }
- FcMemAlloc (FC_MEM_STRING, 1000);
- if(!GetModuleFileName(NULL, data, 1000))
+ data = buffer;
+ if (!GetModuleFileName (NULL, buffer, sizeof (buffer) - 20))
{
FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
- FcStrFree (data);
break;
}
p = strrchr (data, '\\');
@@ -2092,19 +2079,11 @@ FcEndElement(void *userData, const XML_Char *name)
else if (strcmp (data, "WINDOWSFONTDIR") == 0)
{
int rc;
- FcStrFree (data);
- data = malloc (1000);
- if (!data)
- {
- FcConfigMessage (parse, FcSevereError, "out of memory");
- break;
- }
- FcMemAlloc (FC_MEM_STRING, 1000);
- rc = GetSystemWindowsDirectory (data, 800);
- if (rc == 0 || rc > 800)
+ data = buffer;
+ rc = GetSystemWindowsDirectory (buffer, sizeof (buffer) - 20);
+ if (rc == 0 || rc > sizeof (buffer) - 20)
{
FcConfigMessage (parse, FcSevereError, "GetSystemWindowsDirectory failed");
- FcStrFree (data);
break;
}
if (data [strlen (data) - 1] != '\\')
commit a1b6e34a9a17a4a675bdc993aa465b92d7122376
Author: Tor Lillqvist <tml at iki.fi>
Date: Fri Aug 14 00:02:59 2009 +0300
Fix MinGW compilation
Need to define _WIN32_WINNT as 0x0500 to get declaration for
GetSystemWindowsDirectory().
diff --git a/src/fcxml.c b/src/fcxml.c
index 9dc64e2..7b7bbfd 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -53,6 +53,7 @@
#endif /* ENABLE_LIBXML2 */
#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
#define STRICT
#include <windows.h>
#undef STRICT
More information about the Fontconfig
mailing list