From b0a5b4b48e9c94bcebe902fb88fbe447f2ccd04e Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Thu, 8 Jun 2017 09:34:53 +0200 Subject: [PATCH] FcLangSetCompare(): fix bug when two charsets come from different "buckets" In fcLangCountrySets, it may happen that two charsets for the same language but different territories are found in different FcChar32 "buckets" (different "columns" on the same line). This is currently the case for the following pairs: mn-cn and mn-mn pap-an and pap-aw The FcLangSetCompare() code so far used to return FcLangDifferentLang instead of FcLangDifferentTerritory when comparing: an FcLangSet containing only mn-cn with one containing only mn-mn or an FcLangSet containing only pap-an with one containing only pap-aw This commit fixes this problem. --- src/fclang.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/fclang.c b/src/fclang.c index dbbe721..18a373c 100644 --- a/src/fclang.c +++ b/src/fclang.c @@ -680,6 +680,7 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb) { int i, j, count; FcLangResult best, r; + FcChar32 aInCountrySet, bInCountrySet; count = FC_MIN (lsa->map_size, lsb->map_size); count = FC_MIN (NUM_LANG_SET_MAP, count); @@ -688,13 +689,22 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb) return FcLangEqual; best = FcLangDifferentLang; for (j = 0; j < NUM_COUNTRY_SET; j++) + { + aInCountrySet = 0; + bInCountrySet = 0; + for (i = 0; i < count; i++) - if ((lsa->map[i] & fcLangCountrySets[j][i]) && - (lsb->map[i] & fcLangCountrySets[j][i])) + { + aInCountrySet |= lsa->map[i] & fcLangCountrySets[j][i]; + bInCountrySet |= lsb->map[i] & fcLangCountrySets[j][i]; + + if (aInCountrySet && bInCountrySet) { best = FcLangDifferentTerritory; break; } + } + } if (lsa->extra) { r = FcLangSetCompareStrSet (lsb, lsa->extra);