Commit Graph

78 Commits

Author SHA1 Message Date
Taylor R Campbell 7dfde9b736 Avoid misuse of ctype(3)
The ctype(3) functions take arguments of type int that are either

(a) EOF, or
(b) unsigned char values, {0, 1, 2, ..., 255} if char is 8-bit.

Passing values of type char, on platforms where it is signed, can go
wrong -- negative values may be confused with EOF (typically -1) or
may lead to undefined behaviour ranging in practice from returning
garbage data (possibly out of an adjacent buffer in memory that may
contain secrets) to crashing with SIGSEGV (if the page preceding the
ctype table is unmapped).

The ctype(3) functions can't themselves convert to unsigned char
because then they would give the wrong answers for EOF, for use with
functions like getchar and fgetc; the user has to cast char to
unsigned char.
2022-04-11 12:27:04 +00:00
Alex Richardson 92ed966b74 FcCharSetPutLeaf(): Fix missing move of new_leaves contents
If the `realloc(numbers)` call fails, shrinking the leaves allocation
back to the old size is not guaranteed to return the old pointer value.
While this might be the case with some malloc() implementations, realloc()
could also just mark the following area as free.
To make this less error-prone, we grow numbers first and then grow leaves
since the numbers content does not need to be relocated, but leaves does.

See https://bugs.freedesktop.org/show_bug.cgi?id=90867
2021-08-18 10:36:47 +01:00
Behdad Esfahbod fd2ad1147a Fix undefined-behavior signed shifts 2018-01-09 11:03:31 +01:00
Florent Rougon 60e1fe550a 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.
2017-06-12 17:03:37 +09:00
Florent Rougon c37eeb8f1f FcCharSetHash(): use the 'numbers' values to compute the hash
Before this commit, FcCharSetHash() repeatedly used the address of the
'numbers' array of an FcCharSet to compute the FcCharSet hash, instead
of the value of each array element. This is not good for even spreading
of the FcCharSet objects among the various buckets of the hash table
(and should thus reduce performance). This bug appears to have been
mistakenly introduced in commit
cd2ec1a940 (June 2005).
2017-06-07 11:17:15 +09:00
Akira TAGOH a8096dfa59 Bug 90867 - Memory Leak during error case in fccharset
https://bugs.freedesktop.org/show_bug.cgi?id=90867
2015-06-24 15:46:45 +09:00
Behdad Esfahbod f5b4b2c1ed Fix charset unparse after recent changes 2014-07-04 01:43:47 -04:00
Behdad Esfahbod 940d27a197 Minor 2014-07-03 21:15:25 -04:00
Behdad Esfahbod e708e97c35 Change charset parse/unparse format to be human readable
Previous format was unusable.  New format is ranges of hex values.
To choose space character and Latin capital letters for example:

$ fc-pattern ':charset=20 41-5a'
Pattern has 1 elts (size 16)
	charset:
	0000: 00000000 00000001 07fffffe 00000000 00000000 00000000 00000000 00000000
(s)
2014-07-03 17:54:11 -04:00
Akira TAGOH 48c8b7938a Allow the modification on FcTypeVoid with FcTypeLangSet and FcTypeCharSet
FcTypeVoid is likely to happen when 'lang' and 'charset'
is deleted by 'delete' or 'delete_all' mode in edit.
Without this change, any modification on them are simply
ignored.

This is useful to make a lot of changes, particularly
when one wants to add a few and delete a lot say.
2014-05-13 21:22:17 +09:00
Behdad Esfahbod 64af9e1917 Make refcounts, patterns, charsets, strings, and FcLang thread-safe 2013-01-02 00:51:00 -06:00
Behdad Esfahbod d7e1965aa0 Remove memory accounting and reporting
That belongs in tools like cairo/util/malloc-stat.so
2012-12-29 23:12:07 -05:00
Behdad Esfahbod 83d8019011 Fix unused-parameter warnings 2012-12-29 22:32:56 -05:00
Akira TAGOH 0ca752dd25 Check null value for given object to avoid possibly segfaulting 2012-03-07 17:56:39 +09:00
Behdad Esfahbod 5aaf466d38 Cleanup copyright notices to replace "Keith Packard" with "the author(s)" 2010-11-10 16:45:42 -05:00
Behdad Esfahbod 52960d05eb Add new public API: FcCharSetDelChar() 2010-09-21 13:14:41 -04:00
Behdad Esfahbod 594dcef0f3 Remove all training whitespaces 2010-04-12 12:19:05 -04:00
Behdad Esfahbod 77f4e60a32 Remove bogus comment
Last night in between my dreams I also noticed that we support Unicode
values up to 0x01000000 and not 0x00100000 which I thought before.
This covers the entire Unicode range.
2009-11-18 09:10:05 -05:00
Behdad Esfahbod 900723f3d2 [charset] Grow internal FcCharset arrays exponentially 2009-06-24 13:52:12 -04:00
Behdad Esfahbod cce69b07ef Always set *changed in FcCharsetMerge 2009-06-24 13:52:12 -04:00
Behdad Esfahbod 86bdf4598f Add XXX note about Unicode Plane 16 2009-06-24 13:52:12 -04:00
Behdad Esfahbod 3074a73b41 Replace 'KEITH PACKARD' with 'THE AUTHOR(S)' in license text in all files 2009-03-13 17:59:28 -04:00
Karl Tomlinson 575ee6cddd Change FcCharSetMerge API
To only work on writable charsets.  Also, return a bool indicating whether
the merge changed the charset.

Also changes the implementation of FcCharSetMerge and FcCharSetIsSubset
2009-02-15 13:40:18 -08:00
Behdad Esfahbod 25a09eb9bf Don't use FcCharSetCopy in FcCharSetMerge
The Copy function is actually a ref, not real copy.
2009-02-13 16:54:06 -08:00
Behdad Esfahbod 350dc5f350 Use __builtin_popcount() when available (bug #17592) 2009-02-13 16:54:02 -08:00
Chris Wilson 311da2316f Reduce number of allocations during FcSortWalk().
The current behaviour of FcSortWalk() is to create a new FcCharSet on
each iteration that is the union of the previous iteration with the next
FcCharSet in the font set. This causes the existing FcCharSet to be
reproduced in its entirety and then allocates fresh leaves for the new
FcCharSet. In essence the number of allocations is quadratic wrt the
number of fonts required.

By introducing a new method for merging a new FcCharSet with an existing
one we can change the behaviour to be effectively linear with the number
of fonts - allocating no more leaves than necessary to cover all the
fonts in the set.

For example, profiling 'gedit UTF-8-demo.txt'
    Allocator		    nAllocs	    nBytes
Before:
    FcCharSetFindLeafCreate 62886	    2012352
    FcCharSetPutLeaf        9361	    11441108
After:
    FcCharSetFindLeafCreate 1940	    62080
    FcCharSetPutLeaf        281		    190336

The savings are even more significant for applications like firefox-3.0b5
which need to switch between large number of fonts.
Before:
    FcCharSetFindLeafCreate 4461192	    142758144
    FcCharSetPutLeaf	    1124536	    451574172
After:
    FcCharSetFindLeafCreate 80359	    2571488
    FcCharSetPutLeaf	    18940	    9720522

Out of interest, the next most frequent allocations are
    FcPatternObjectAddWithBinding 526029    10520580
    tt_face_load_eblc	    42103	    2529892
2009-02-13 16:54:00 -08:00
Behdad Esfahbod 317b849215 Replace RCS Id tags with the file name 2009-02-13 16:53:55 -08:00
Keith Packard 13a14cbf56 Fix a few memory tracking mistakes.
The built-in memory tracking code in fontconfig relies on a lot of manual
function call tracking. A pain, but it helps debug leaks.
2008-05-04 01:26:40 -07:00
Keith Packard c3796ac606 Charset hashing depended on uniqueness of leaves.
Charset hashing actually use the value of the leaf pointers, which is
clearly wrong, especially now that charsets are not shared across multiple
font directories.
2006-09-06 17:45:40 -07:00
Keith Packard 23816bf9ac Eliminate .so PLT entries for local symbols. (thanks to Arjan van de Ven)
Using a simple shell script that processes the public headers, two header
files are constructed that map public symbols to hidden internal aliases
avoiding the assocated PLT entry for referring to a public symbol.

A few mistakes in the FcPrivate/FcPublic annotations were also discovered
through this process
2006-09-05 02:24:01 -07:00
Keith Packard 9e612141df Reference count cache objects.
Caches contain patterns and character sets which are reference counted and
visible to applications. Reference count the underlying cache object so that
it stays around until all reference objects are no longer in use.

This is less efficient than just leaving all caches around forever, but does
avoid eternal size increases in case applications ever bother to actually
look for changes in the font configuration.
2006-09-04 22:20:25 -07:00
Keith Packard 4984242e36 Hide private functions in shared library. Export functionality for utilities.
Borrowing header stuff written for cairo, fontconfig now exposes in the
shared library only the symbols which are included in the public header
files. All private symbols are hidden using suitable compiler directives.

A few new public functions were required for the fontconfig utility programs
(fc-cat and fc-cache) so those were added, bumping the .so minor version number
in the process.
2006-09-04 00:47:07 -07:00
Keith Packard 18b6857c64 Fix fc-lang to use new charset freezer API.
Charset freezer api now uses allocated object. Also required minor fixes to
charset freezer code to remove assumption that all input charsets are
persistant.
2006-09-01 01:49:47 -07:00
Keith Packard bc5e487f2a Pass directory information around in FcCache structure. Freeze charsets.
Instead of passing directory information around in separate variables,
collect it all in an FcCache structure. Numerous internal and tool
interfaces changed as a result of this.

Charsets are now pre-frozen before being serialized. This causes them to
share across multiple fonts in the same cache.
2006-09-01 01:15:14 -07:00
Keith Packard 2d3387fd72 Skip broken caches. Cache files are auto-written, don't rewrite in fc-cache.
Validate cache contents and skip broken caches, looking down cache path for
valid ones.

Every time a directory is scanned, it will be written to a cache file if
possible, so fc-cache doesn't need to re-write the cache file. This makes
detecting when the cache was generated a bit tricky, so we guess that if the
cache wasn't valid before running and is valid afterwards, the cache file
was written.

Also, allow empty charsets to be serialized with null leaves/numbers.

Eliminate a leak in FcEdit by switching to FcObject sooner.

Call FcFini from fc-match to make valgrind happy.
2006-08-30 21:59:53 -07:00
Keith Packard c02886485b FcCharSetSerialize was using wrong offset for leaves. Make fc-cat work.
FcCharSetSerialize was computing the offset to the unserialized leaf,
which left it pointing at random data when the cache was reloaded.

fc-cat has been updated to work with the new cache structure.

Various debug messages extended to help diagnose serialization errors.
2006-08-30 13:51:03 -07:00
Keith Packard 7ce1967331 Rework cache files to use offsets for all data structures.
Replace all of the bank/id pairs with simple offsets, recode several
data structures to always use offsets inside the library to avoid
conditional paths. Exposed data structures use pointers to hold offsets,
setting the low bit to distinguish between offset and pointer.

Use offset-based data structures for lang charset encodings; eliminates
separate data structure format for that file.

Much testing will be needed; offsets are likely not detected everywhere in
the library yet.
2006-08-30 04:16:22 -07:00
Patrick Lam f045376c08 Include $(top_srcdir), $(top_srcdir)/src before anything else.
Shuffle order of includes for building out of srcdir on win32.
reviewed by: plam
2006-04-25 05:57:41 +00:00
Patrick Lam 2de24638b2 Missing bits from previous patches.
Remove extra semi-colon.
Fix memory leak in error case (Coverity defects #776, #985).
Fix memory leaks (Coverity defects #779, #781) and memory use after free
    (Coverity defect #780).
reviewed by: plam
2006-04-11 16:54:24 +00:00
Patrick Lam 04f7d3e7fd Properly convert static charsets to dynamic charsets.
Fix memory leak in error case (Coverity defects #1820, #1821, #1822).
Fix memory leak (Coverity defect #1819).
prevent crash when invalid include line is parsed (Coverity defect #763).
Fix potential null pointer access (Coverity defect #1804).
Remove dead code (Coverity defect #1194).
Prevent potential null pointer access (Coverity defect #767), ensure error
    value is read (Coverity defect #1195).
reviewed by: plam
2006-04-11 14:20:59 +00:00
Patrick Lam 44415a079a Portability fixes for HP-UX (reported by Christoph Bauer). Replace
'__inline__' by AC_C_INLINE and 'inline'. Replace '__alignof__' by
    'fc_alignof'.
reviewed by: plam
2006-04-07 17:27:39 +00:00
Patrick Lam a8c425301a Fix problem with missing 'en' due to euro.patch: change cache file format
slightly to coincide with that generated by fc-lang.
2006-02-09 15:25:57 +00:00
Patrick Lam 6cc02fe6b9 src/fccharset.c (FcLangCharSetPopulate, FcCharSetInsertLeaf)
Fix missing FcCacheBankToIndex in FcCharSetInsertLeaf. Declare extern for
    static arrays as arrays, not pointers. (Part of the fix for 'fonts
    don't have en' issue after Euro patch.)
(I forgot to commit the ChangeLog last time.)
reviewed by: plam
2006-02-07 20:56:48 +00:00
Patrick Lam a81f23c0ce Fix hidden variable warning. 2006-02-07 03:53:32 +00:00
Patrick Lam 19ea60bc7c Avoid check on _fcBankId nullness and fix case where it used to crash. 2005-12-21 05:37:10 +00:00
Patrick Lam 61571f3f2e Pass around FcCache *s to the Unserialize functions for extra consistency
(and less overhead, for what that's worth).
2005-11-25 15:50:34 +00:00
Patrick Lam 1c5b6345b9 Don't add current_arch_start more than once.
Fix ordering of ALIGN with respect to saving block_ptr; add another ALIGN
    to fcfs.c.
reviewed by: plam
2005-11-17 15:43:39 +00:00
Patrick Lam 7fd7221e68 Add *NeededBytesAlign(), which overestimates the padding which is later
added by the new ALIGN macro. Fix alignment problems on ia64 and s390
    by bumping up block_ptr appropriately. (Earlier version by Andreas
    Schwab).
Use sysconf to determine proper PAGESIZE value; this appears to be
    POSIX-compliant. (reported by Andreas Schwab)
reviewed by: plam
2005-11-16 15:55:17 +00:00
Patrick Lam 82f35f8bb4 Fix bug 2878 (excessive relocations at startup for charsets, reported by
Ross Burton): fc-lang/fc-lang now creates the static form of the
    langset, not the dynamic form, so that the charsets should now be in
    .rodata.
2005-11-04 19:31:26 +00:00
Patrick Lam 67accef4d3 Fix more gcc4 warnings:
- Cast sizeof to int, to shut up signedness warnings in comparison.
- Add consts where appropriate.
reviewed by: Patrick Lam <plam@mit.edu>
2005-09-22 23:45:53 +00:00