]> git.wh0rd.org - fontconfig.git/commitdiff
src/fccache.c (FcDirCacheProduce)
authorPatrick Lam <plam@MIT.EDU>
Wed, 16 Nov 2005 17:49:01 +0000 (17:49 +0000)
committerPatrick Lam <plam@MIT.EDU>
Wed, 16 Nov 2005 17:49:01 +0000 (17:49 +0000)
Fix case where alignment bytes bumped up metadata->count causing
    unwarranted failures to write cache files. (Reported by Stephan Kulow).

ChangeLog
src/fccache.c

index f2b0ec28b9afdde79717fffaae38304f89ed2f25..f803d66a6404821dd8faa8efb1324fe320c8920d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-11-16  Patrick Lam  <plam@mit.edu>
+       * src/fccache.c (FcDirCacheProduce)
+       
+       Fix case where alignment bytes bumped up metadata->count
+       causing unwarranted failures to write cache files.  
+       (Reported by Stephan Kulow).
+
 2005-11-16  Patrick Lam  <plam@mit.edu>
        * src/fccache.c (FcDirCacheProduce):
        * src/fccharset.c (FcCharSetDistributeBytes):
index af8a318c43e4f5743b693b548f9f16bbc458e9fe..84a366e662469daa9d56c575e314c595c9ecaa3c 100644 (file)
@@ -793,7 +793,7 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
 {
     void * current_dir_block, * final_dir_block;
     static unsigned int rand_state = 0;
-    int bank;
+    int bank, needed_bytes_no_align;
 
     if (!rand_state) 
        rand_state = time(0L);
@@ -804,20 +804,27 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata)
 
     memset (metadata, 0, sizeof(FcCache));
     FcFontSetNewBank();
-    metadata->count = FcFontSetNeededBytes (set) + 
+    needed_bytes_no_align = FcFontSetNeededBytes (set);
+    metadata->count = needed_bytes_no_align + 
        FcFontSetNeededBytesAlign ();
     metadata->magic = FC_CACHE_MAGIC;
     metadata->bank = bank;
 
-    if (!metadata->count) /* not a failure, no fonts to write */
+    if (!needed_bytes_no_align) /* not a failure, no fonts to write */
+    {
+       /* no, you don't really need to write any bytes at all. */
+       metadata->count = 0;
        return 0;
+    }
 
     current_dir_block = malloc (metadata->count);
     if (!current_dir_block)
        goto bail;
+    // shut up valgrind
+    memset (current_dir_block, 0, metadata->count);
     final_dir_block = FcFontSetDistributeBytes (metadata, current_dir_block);
 
-    if ((char *)current_dir_block + metadata->count != final_dir_block)
+    if ((void *)((char *)current_dir_block+metadata->count) < final_dir_block)
        goto bail;
                              
     if (!FcFontSetSerialize (bank, set))