Bug 101352 - Weird bucket choice or number in FcCharSetFreezeOrig() and FcCharSetFindFrozen()
Summary: Weird bucket choice or number in FcCharSetFreezeOrig() and FcCharSetFindFrozen()
Status: RESOLVED FIXED
Alias: None
Product: fontconfig
Classification: Unclassified
Component: library (show other bugs)
Version: 2.12
Hardware: All All
: medium minor
Assignee: fontconfig-bugs
QA Contact: Behdad Esfahbod
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-08 14:21 UTC by Florent Rougon
Modified: 2017-06-12 08:03 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Possible fix in 'git format-patch' format (1.90 KB, patch)
2017-06-08 14:21 UTC, Florent Rougon
Details | Splinter Review

Description Florent Rougon 2017-06-08 14:21:11 UTC
Created attachment 131807 [details] [review]
Possible fix in 'git format-patch' format

Hello,

As written at: https://lists.freedesktop.org/archives/fontconfig/2017-June/005929.html

The following looks odd to me in src/fccharset.c:

#define FC_CHAR_SET_HASH_SIZE    67

[...]

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];

[...]

static const FcCharSet *
FcCharSetFindFrozen (FcCharSetFreezer *freezer, const FcCharSet *orig)
{
    FcCharSetOrigEnt    **bucket = &freezer->orig_hash_table[((uintptr_t) orig) & FC_CHAR_SET_HASH_SIZE];

[...]

It seems to me that either FC_CHAR_SET_HASH_SIZE should be defined as a
power of two minus one (2**n - 1 for some n), or the two occurrences of
the & operator in the above lines should be replaced with a % operator.
Otherwise, at most 8 buckets among the 67 available in
freezer->orig_hash_table can effectively be used
(67 = 64 + 2 + 1 and 2**3 = 8).
Comment 1 Akira TAGOH 2017-06-12 08:03:58 UTC
Thanks. merged into git.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.