From 8e351527bb87798e9b796e12a3b1ee6229536a28 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Wed, 16 Nov 2005 17:49:01 +0000 Subject: [PATCH] src/fccache.c (FcDirCacheProduce) Fix case where alignment bytes bumped up metadata->count causing unwarranted failures to write cache files. (Reported by Stephan Kulow). --- ChangeLog | 7 +++++++ src/fccache.c | 15 +++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2b0ec2..f803d66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-11-16 Patrick Lam + * 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 * src/fccache.c (FcDirCacheProduce): * src/fccharset.c (FcCharSetDistributeBytes): diff --git a/src/fccache.c b/src/fccache.c index af8a318..84a366e 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -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)) -- 2.39.5