From 3b2c2df41b90f2a1d9e33b3dc15a92cff58a689a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Apr 2010 16:51:42 -0400 Subject: [PATCH] Cleanup Extension sanitize() --- src/hb-ot-layout-common-private.hh | 20 +++----------------- src/hb-ot-layout-gpos-private.hh | 20 +++++++++++++------- src/hb-ot-layout-gsub-private.hh | 20 +++++++++++++------- src/hb-ot-layout-gsubgpos-private.hh | 13 ++++--------- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 9c3de50..cfbca1d 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -264,21 +264,8 @@ struct LookupFlag : USHORT }; ASSERT_SIZE (LookupFlag, 2); -struct LookupSubTable -{ - inline bool sanitize (SANITIZE_ARG_DEF) { - TRACE_SANITIZE (); - return SANITIZE_SELF (); - } - - private: - USHORT format; /* Subtable format. Different for GSUB and GPOS */ -}; -ASSERT_SIZE (LookupSubTable, 2); - struct Lookup { - inline const LookupSubTable& get_subtable (unsigned int i) const { return this+subTable[i]; } inline unsigned int get_subtable_count (void) const { return subTable.len; } inline unsigned int get_type (void) const { return lookupType; } @@ -295,9 +282,8 @@ struct Lookup inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - /* We sanitize subtables shallow here since we don't have their actual - * type. Real sanitize of the referenced data is done by GSUB/GPOS/... */ - if (!(SANITIZE_SELF () && HB_LIKELY (subTable.sanitize_shallow (SANITIZE_ARG)))) return false; + /* Real sanitize of the subtables is done by GSUB/GPOS/... */ + if (!(SANITIZE_SELF () && HB_LIKELY (subTable.sanitize (SANITIZE_ARG)))) return false; if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet)) { USHORT &markFilteringSet = StructAfter (subTable); @@ -308,7 +294,7 @@ struct Lookup USHORT lookupType; /* Different enumerations for GSUB and GPOS */ USHORT lookupFlag; /* Lookup qualifiers */ - OffsetArrayOf + ArrayOf subTable; /* Array of SubTables */ USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets * structure. This field is only present if bit diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index f5348f4..75dcd4c 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -1358,7 +1358,11 @@ struct ExtensionPos : Extension private: inline const struct PosLookupSubTable& get_subtable (void) const - { return CONST_CAST (PosLookupSubTable, Extension::get_subtable (), 0); } + { + unsigned int offset = get_offset (); + if (HB_UNLIKELY (!offset)) return Null(PosLookupSubTable); + return CONST_CAST (PosLookupSubTable, *this, offset); + } inline bool apply (APPLY_ARG_DEF) const; @@ -1519,7 +1523,7 @@ struct PosLookup : Lookup inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!Lookup::sanitize (SANITIZE_ARG)) return false; + if (HB_UNLIKELY (!Lookup::sanitize (SANITIZE_ARG))) return false; OffsetArrayOf &list = CAST (OffsetArrayOf, subTable, 0); return SANITIZE_THIS (list); } @@ -1550,7 +1554,7 @@ struct GPOS : GSUBGPOS inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!GSUBGPOS::sanitize (SANITIZE_ARG)) return false; + if (HB_UNLIKELY (!GSUBGPOS::sanitize (SANITIZE_ARG))) return false; OffsetTo &list = CAST(OffsetTo, lookupList, 0); return SANITIZE_THIS (list); } @@ -1574,10 +1578,12 @@ inline bool ExtensionPos::apply (APPLY_ARG_DEF) const inline bool ExtensionPos::sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - return Extension::sanitize (SANITIZE_ARG) && - (&(Extension::get_subtable ()) == &Null(LookupSubTable) || - get_type () == PosLookupSubTable::Extension || - DECONST_CAST (PosLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); + if (HB_UNLIKELY (!Extension::sanitize (SANITIZE_ARG))) return false; + if (HB_UNLIKELY (get_type () == PosLookupSubTable::Extension)) return false; + + unsigned int offset = get_offset (); + if (HB_UNLIKELY (!offset)) return true; + return SANITIZE (CAST (PosLookupSubTable, *this, offset)); } static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index) diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 65402b8..23150b6 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -563,7 +563,11 @@ struct ExtensionSubst : Extension private: inline const struct SubstLookupSubTable& get_subtable (void) const - { return CONST_CAST (SubstLookupSubTable, Extension::get_subtable (), 0); } + { + unsigned int offset = get_offset (); + if (HB_UNLIKELY (!offset)) return Null(SubstLookupSubTable); + return CONST_CAST (SubstLookupSubTable, *this, offset); + } inline bool apply (APPLY_ARG_DEF) const; @@ -828,7 +832,7 @@ struct SubstLookup : Lookup inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!Lookup::sanitize (SANITIZE_ARG)) return false; + if (HB_UNLIKELY (!Lookup::sanitize (SANITIZE_ARG))) return false; OffsetArrayOf &list = CAST (OffsetArrayOf, subTable, 0); return SANITIZE_THIS (list); } @@ -860,7 +864,7 @@ struct GSUB : GSUBGPOS inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!GSUBGPOS::sanitize (SANITIZE_ARG)) return false; + if (HB_UNLIKELY (!GSUBGPOS::sanitize (SANITIZE_ARG))) return false; OffsetTo &list = CAST(OffsetTo, lookupList, 0); return SANITIZE_THIS (list); } @@ -884,10 +888,12 @@ inline bool ExtensionSubst::apply (APPLY_ARG_DEF) const inline bool ExtensionSubst::sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - return Extension::sanitize (SANITIZE_ARG) && - (&(Extension::get_subtable ()) == &Null(LookupSubTable) || - get_type () == SubstLookupSubTable::Extension || - DECONST_CAST (SubstLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); + if (HB_UNLIKELY (!Extension::sanitize (SANITIZE_ARG))) return false; + if (HB_UNLIKELY (get_type () == SubstLookupSubTable::Extension)) return false; + + unsigned int offset = get_offset (); + if (HB_UNLIKELY (!offset)) return true; + return SANITIZE (CAST (SubstLookupSubTable, *this, offset)); } static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index) diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 2856d34..3e4adff 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -836,12 +836,7 @@ struct ExtensionFormat1 protected: inline unsigned int get_type (void) const { return extensionLookupType; } - inline const LookupSubTable& get_subtable (void) const - { - unsigned int offset = extensionOffset; - if (HB_UNLIKELY (!offset)) return Null(LookupSubTable); - return CONST_CAST (LookupSubTable, *this, offset); - } + inline unsigned int get_offset (void) const { return extensionOffset; } inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); @@ -867,11 +862,11 @@ struct Extension default:return 0; } } - inline const LookupSubTable& get_subtable (void) const + inline unsigned int get_offset (void) const { switch (u.format) { - case 1: return u.format1->get_subtable (); - default:return Null(LookupSubTable); + case 1: return u.format1->get_offset (); + default:return 0; } } -- 2.7.4