From e3e685e5eec1cb400e0b4bd371872cb9394c79bc Mon Sep 17 00:00:00 2001 From: David Corbett Date: Wed, 18 May 2022 15:05:55 -0400 Subject: [PATCH] [ot-tags] Fix `min_subtag_len` calculations --- src/gen-tag-table.py | 12 +++++------- src/hb-ot-tag-table.hh | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/gen-tag-table.py b/src/gen-tag-table.py index 9f6080fa2..b87183604 100755 --- a/src/gen-tag-table.py +++ b/src/gen-tag-table.py @@ -1019,14 +1019,12 @@ for initial, items in sorted (complex_tags.items ()): if not tags: continue subtag_len = 0 - subtag_len += len(lt.script) if lt.script is not None else 0 - subtag_len += len(lt.region) if lt.region is not None else 0 - subtag_len += len(lt.variant) if lt.variant is not None else 0 + subtag_len += 1 + len (lt.script) if lt.script is not None else 0 + subtag_len += 1 + len (lt.region) if lt.region is not None else 0 + subtag_len += 1 + len (lt.variant) if lt.variant is not None else 0 min_subtag_len = min(subtag_len, min_subtag_len) -min_subtag_len += 1 # For initial '-' -print (' if (limit - lang_str > %d ||' % min_subtag_len) -print (" (limit - lang_str == %d && *lang_str == '-'))" % min_subtag_len) +print (' if (limit - lang_str >= %d)' % (min_subtag_len + 2)) print (' {') print (" const char *p = strchr (lang_str, '-');") print (" if (!p || p >= limit || limit - p < %i) goto out;" % min_subtag_len) @@ -1058,7 +1056,7 @@ for initial, items in sorted (complex_tags.items ()): print () print (' };') print (' for (i = 0; i < %s && i < *count; i++)' % len (tags)) - print (' tags[i] = possible_tags[i];') + print ('\ttags[i] = possible_tags[i];') print (' *count = i;') print (' return true;') print (' }') diff --git a/src/hb-ot-tag-table.hh b/src/hb-ot-tag-table.hh index ecf6d339f..b242fba2d 100644 --- a/src/hb-ot-tag-table.hh +++ b/src/hb-ot-tag-table.hh @@ -1642,8 +1642,7 @@ hb_ot_tags_from_complex_language (const char *lang_str, unsigned int *count /* IN/OUT */, hb_tag_t *tags /* OUT */) { - if (limit - lang_str > 5 || - (limit - lang_str == 5 && *lang_str == '-')) + if (limit - lang_str >= 7) { const char *p = strchr (lang_str, '-'); if (!p || p >= limit || limit - p < 5) goto out;