]> git.wh0rd.org - fontconfig.git/commitdiff
Bug 35587 - Add padding to make valgrind and glibc not hate each other
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 28 Mar 2011 20:33:12 +0000 (16:33 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 28 Mar 2011 20:33:12 +0000 (16:33 -0400)
src/fccfg.c
src/fcpat.c

index 4beb7d23688b8f97a423e60d85de4f34cf873bca..09c59919d8f37bd1998f7d530f7b96865512b8a2 100644 (file)
@@ -1689,10 +1689,19 @@ static FcChar8 *
 FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
 {
     FcChar8    *path;
+    int         size;
 
     if (!dir)
        dir = (FcChar8 *) "";
-    path = malloc (strlen ((char *) dir) + 1 + strlen ((char *) file) + 1);
+
+    size = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1;
+    /*
+     * workaround valgrind warning because glibc takes advantage of how it knows memory is
+     * allocated to implement strlen by reading in groups of 4
+     */
+    size = (size + 3) & ~3;
+
+    path = malloc (size);
     if (!path)
        return 0;
 
@@ -1711,7 +1720,7 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
 #endif
     strcat ((char *) path, (char *) file);
 
-    FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1);
+    FcMemAlloc (FC_MEM_STRING, size);
     if (access ((char *) path, R_OK) == 0)
        return path;
 
index be01a4fd25a46906de26916b0b2b37892eb04b19..8f63659df673c2f204ec7bb5fe2ddeac6bff9dee 100644 (file)
@@ -1057,9 +1057,13 @@ FcStrStaticName (const FcChar8 *name)
        if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
            return (FcChar8 *) (b + 1);
     size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
-    b = malloc (size + sizeof (int));
-    /* workaround glibc bug which reads strlen in groups of 4 */
-    FcMemAlloc (FC_MEM_STATICSTR, size + sizeof (int));
+    /*
+     * workaround valgrind warning because glibc takes advantage of how it knows memory is
+     * allocated to implement strlen by reading in groups of 4
+     */
+    size = (size + 3) & ~3;
+    b = malloc (size);
+    FcMemAlloc (FC_MEM_STATICSTR, size);
     if (!b)
         return NULL;
     b->next = 0;