From 60e1fe550ae5d945c45a7ad04b46ec78da0309aa Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Thu, 8 Jun 2017 16:13:29 +0200 Subject: [PATCH] FcCharSetFreezeOrig(), FcCharSetFindFrozen(): use all buckets of freezer->orig_hash_table As written at: https://lists.freedesktop.org/archives/fontconfig/2017-June/005929.html I think FcCharSetFreezeOrig() and FcCharSetFindFrozen() should use the % operator instead of & when computing the bucket index for freezer->orig_hash_table, otherwise at most 8 buckets among the 67 available (FC_CHAR_SET_HASH_SIZE) are used. Another way would be to change FC_CHAR_SET_HASH_SIZE to be of the form 2**n -1 (i.e., a power of two minus one). In such a case, the & and % operators would be equivalent. --- src/fccharset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fccharset.c b/src/fccharset.c index 6e69f66..69fbf66 100644 --- a/src/fccharset.c +++ b/src/fccharset.c @@ -1120,7 +1120,7 @@ FcCharSetHash (FcCharSet *fcs) static FcBool FcCharSetFreezeOrig (FcCharSetFreezer *freezer, const FcCharSet *orig, const FcCharSet *frozen) { - FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; + FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) % FC_CHAR_SET_HASH_SIZE]; FcCharSetOrigEnt *ent; ent = malloc (sizeof (FcCharSetOrigEnt)); @@ -1204,7 +1204,7 @@ FcCharSetFreezeBase (FcCharSetFreezer *freezer, FcCharSet *fcs) static const FcCharSet * FcCharSetFindFrozen (FcCharSetFreezer *freezer, const FcCharSet *orig) { - FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE]; + FcCharSetOrigEnt **bucket = &freezer->orig_hash_table[((uintptr_t) orig) % FC_CHAR_SET_HASH_SIZE]; FcCharSetOrigEnt *ent; for (ent = *bucket; ent; ent = ent->next)