]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcstr.c
Avoid crash when $HOME is not set
[fontconfig.git] / src / fcstr.c
index fadc1de7ce33e845699aae96e264084474f19315..3a31b22584b976b4ef775c033eee4b3ed11487fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcstr.c,v 1.7 2002/07/13 05:43:25 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcstr.c,v 1.10 2002/08/31 22:17:32 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -283,7 +283,7 @@ FcUtf16ToUcs4 (const FcChar8        *src_orig,
        if ((b & 0xfc00) != 0xdc00)
            return 0;
        result = ((((FcChar32) a & 0x3ff) << 10) |
-                 ((FcChar32) b & 0x3ff)) | 0x10000;
+                 ((FcChar32) b & 0x3ff)) + 0x10000;
     }
     else
        result = a;
@@ -341,6 +341,7 @@ FcStrBufDestroy (FcStrBuf *buf)
 {
     if (buf->allocated)
     {
+       FcMemFree (FC_MEM_STRBUF, buf->size);
        free (buf->buf);
        FcStrBufInit (buf, 0, 0);
     }
@@ -354,6 +355,7 @@ FcStrBufDone (FcStrBuf *buf)
     ret = malloc (buf->len + 1);
     if (ret)
     {
+       FcMemAlloc (FC_MEM_STRING, buf->len + 1);
        memcpy (ret, buf->buf, buf->len);
        ret[buf->len] = '\0';
     }
@@ -389,6 +391,9 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c)
            buf->failed = FcTrue;
            return FcFalse;
        }
+       if (buf->size)
+           FcMemFree (FC_MEM_STRBUF, buf->size);
+       FcMemAlloc (FC_MEM_STRBUF, size);
        buf->size = size;
        buf->buf = new;
     }
@@ -423,9 +428,10 @@ FcStrCopyFilename (const FcChar8 *s)
     if (*s == '~')
     {
        FcChar8 *home = (FcChar8 *) getenv ("HOME");
-       int     size = strlen ((char *) home) + strlen ((char *) s);
+       int     size;
        if (!home)
            return 0;
+       size = strlen ((char *) home) + strlen ((char *) s);
        new = (FcChar8 *) malloc (size);
        if (!new)
            return 0;