diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 47d4e04ff..dda6b9453 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -122,9 +122,9 @@ typedef struct OffsetTable USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */ USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */ USHORT rangeShift; /* NumTables x 16-searchRange. */ - TableDirectory tableDir[]; /* TableDirectory entries. numTables items */ + TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */ } OpenTypeFontFace; -ASSERT_SIZE (OffsetTable, 12); +ASSERT_SIZE_VAR (OffsetTable, 12, TableDirectory); /* * TrueType Collections diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 4061cfe88..9530c289b 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -50,6 +50,9 @@ #define CONST_NEXT(T,X) (*(reinterpret_cast(CONST_CHARP(&(X)) + (X).get_size ()))) #define NEXT(T,X) (*(reinterpret_cast(CHARP(&(X)) + (X).get_size ()))) +#define CONST_ARRAY_AFTER(T,X) ((reinterpret_cast(CONST_CHARP(&(X)) + sizeof (X)))) +#define ARRAY_AFTER(T,X) ((reinterpret_cast(CHARP(&(X)) + sizeof (X)))) + /* * Class features */ @@ -58,7 +61,7 @@ /* Null objects */ /* Global nul-content Null pool. Enlarge as necessary. */ -static const char NullPool[16] = ""; +static const char NullPool[32] = ""; /* Generic template for nul-content sizeof-sized Null objects. */ template @@ -505,13 +508,16 @@ struct LongOffsetTo : GenericOffsetTo {}; template struct GenericArrayOf { + const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); } + Type *array(void) { return ARRAY_AFTER (Type, len); } + inline const Type& operator [] (unsigned int i) const { if (HB_UNLIKELY (i >= len)) return Null(Type); - return array[i]; + return const_array()[i]; } inline unsigned int get_size () const - { return sizeof (len) + len * sizeof (array[0]); } + { return sizeof (len) + len * sizeof (Type); } inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); @@ -523,7 +529,7 @@ struct GenericArrayOf return true; unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (!SANITIZE (array[i])) + if (!SANITIZE (array()[i])) return false; return true; } @@ -532,7 +538,7 @@ struct GenericArrayOf if (!SANITIZE_GET_SIZE()) return false; unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (!array[i].sanitize (SANITIZE_ARG, base)) + if (!array()[i].sanitize (SANITIZE_ARG, base)) return false; return true; } @@ -541,7 +547,7 @@ struct GenericArrayOf if (!SANITIZE_GET_SIZE()) return false; unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (!array[i].sanitize (SANITIZE_ARG, base, base2)) + if (!array()[i].sanitize (SANITIZE_ARG, base, base2)) return false; return true; } @@ -550,13 +556,13 @@ struct GenericArrayOf if (!SANITIZE_GET_SIZE()) return false; unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (!array[i].sanitize (SANITIZE_ARG, base, user_data)) + if (!array()[i].sanitize (SANITIZE_ARG, base, user_data)) return false; return true; } LenType len; - Type array[]; +/*Type array[VAR];*/ }; /* An array with a USHORT number of elements. */ @@ -586,7 +592,7 @@ struct OffsetListOf : OffsetArrayOf inline const Type& operator [] (unsigned int i) const { if (HB_UNLIKELY (i >= this->len)) return Null(Type); - return this+this->array[i]; + return this+this->const_array()[i]; } inline bool sanitize (SANITIZE_ARG_DEF) { @@ -605,13 +611,16 @@ struct OffsetListOf : OffsetArrayOf template struct HeadlessArrayOf { + const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); } + Type *array(void) { return ARRAY_AFTER (Type, len); } + inline const Type& operator [] (unsigned int i) const { if (HB_UNLIKELY (i >= len || !i)) return Null(Type); - return array[i-1]; + return const_array()[i-1]; } inline unsigned int get_size () const - { return sizeof (len) + (len ? len - 1 : 0) * sizeof (array[0]); } + { return sizeof (len) + (len ? len - 1 : 0) * sizeof (Type); } inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); @@ -622,14 +631,15 @@ struct HeadlessArrayOf * do have a simple sanitize(). */ return true; unsigned int count = len ? len - 1 : 0; + Type *a = array(); for (unsigned int i = 0; i < count; i++) - if (!SANITIZE (array[i])) + if (!SANITIZE (a[i])) return false; return true; } USHORT len; - Type array[]; +/*Type array[VAR];*/ }; diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 0df4a5eb5..3d1bc34a8 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -67,14 +67,15 @@ struct RecordArrayOf : ArrayOf > { inline const Tag& get_tag (unsigned int i) const { if (HB_UNLIKELY (i >= this->len)) return Null(Tag); - return this->array[i].tag; + return (*this)[i].tag; } inline bool get_tags (unsigned int *record_count /* IN/OUT */, hb_tag_t *record_tags /* OUT */) const { + const Record *a = this->const_array(); unsigned int count = MIN (this->len, *record_count); for (unsigned int i = 0; i < count; i++) - record_tags[i] = this->array[i].tag; + record_tags[i] = a[i].tag; *record_count = this->len; return !!this->len; @@ -83,10 +84,11 @@ struct RecordArrayOf : ArrayOf > { { const Tag t = tag; // TODO bsearch + const Record *a = this->const_array(); unsigned int count = this->len; for (unsigned int i = 0; i < count; i++) { - if (t == this->array[i].tag) + if (t == a[i].tag) { if (index) *index = i; return true; @@ -116,14 +118,15 @@ struct IndexArray : ArrayOf { if (HB_UNLIKELY (i >= this->len)) return NO_INDEX; - return this->array[i]; + return this->const_array()[i]; } inline bool get_indexes (unsigned int *_count /* IN/OUT */, unsigned int *_indexes /* OUT */) const { unsigned int count = MIN (this->len, *_count); + const USHORT *a = this->const_array(); for (unsigned int i = 0; i < count; i++) - _indexes[i] = this->array[i]; + _indexes[i] = a[i]; *_count = this->len; return !!this->len; @@ -283,7 +286,7 @@ struct Lookup inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!(SANITIZE_SELF () && SANITIZE_THIS (subTable))) return false; + if (!(SANITIZE_SELF/*XXXXXXXXXXXXXX*/ () && SANITIZE_THIS (subTable))) return false; if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet)) { USHORT &markFilteringSet = NEXT (USHORT, subTable); @@ -296,11 +299,11 @@ struct Lookup USHORT lookupFlag; /* Lookup qualifiers */ OffsetArrayOf subTable; /* Array of SubTables */ - USHORT markFilteringSetX[0]; /* Index (base 0) into GDEF mark glyph sets + USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets * structure. This field is only present if bit * UseMarkFilteringSet of lookup flags is set. */ }; -ASSERT_SIZE (Lookup, 6); +ASSERT_SIZE_VAR (Lookup, 6, USHORT); typedef OffsetListOf LookupList; ASSERT_SIZE (LookupList, 2); @@ -425,11 +428,10 @@ struct Coverage private: union { USHORT format; /* Format identifier */ - CoverageFormat1 format1[]; - CoverageFormat2 format2[]; + CoverageFormat1 format1[VAR]; + CoverageFormat2 format2[VAR]; } u; }; -ASSERT_SIZE (Coverage, 2); /* @@ -541,11 +543,10 @@ struct ClassDef private: union { USHORT format; /* Format identifier */ - ClassDefFormat1 format1[]; - ClassDefFormat2 format2[]; + ClassDefFormat1 format1[VAR]; + ClassDefFormat2 format2[VAR]; } u; }; -ASSERT_SIZE (ClassDef, 2); /* @@ -595,9 +596,9 @@ struct Device USHORT startSize; /* Smallest size to correct--in ppem */ USHORT endSize; /* Largest size to correct--in ppem */ USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */ - USHORT deltaValue[]; /* Array of compressed data */ + USHORT deltaValue[VAR]; /* Array of compressed data */ }; -ASSERT_SIZE (Device, 6); +ASSERT_SIZE_VAR (Device, 6, USHORT); #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 1eb96c0d0..69f90fec1 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -177,12 +177,11 @@ struct CaretValue private: union { USHORT format; /* Format identifier */ - CaretValueFormat1 format1[]; - CaretValueFormat2 format2[]; - CaretValueFormat3 format3[]; + CaretValueFormat1 format1[VAR]; + CaretValueFormat2 format2[VAR]; + CaretValueFormat3 format3[VAR]; } u; }; -ASSERT_SIZE (CaretValue, 2); struct LigGlyph { @@ -286,10 +285,9 @@ struct MarkGlyphSets private: union { USHORT format; /* Format identifier */ - MarkGlyphSetsFormat1 format1[]; + MarkGlyphSetsFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (MarkGlyphSets, 2); /* @@ -364,12 +362,12 @@ struct GDEF * mark attachment type--from beginning * of GDEF header (may be Null) */ OffsetTo - markGlyphSetsDef[0]; /* Offset to the table of mark set + markGlyphSetsDef[VAR]; /* Offset to the table of mark set * definitions--from beginning of GDEF * header (may be NULL). Introduced * in version 00010002. */ }; -ASSERT_SIZE (GDEF, 12); +ASSERT_SIZE_VAR (GDEF, 12, OffsetTo); #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */ diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 609ebe783..5d9fd48e0 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -35,8 +35,8 @@ typedef SHORT Value; -typedef Value ValueRecord[0]; -ASSERT_SIZE (ValueRecord, 0); +typedef Value ValueRecord[VAR]; +ASSERT_SIZE_VAR (Value, 0, ValueRecord); struct ValueFormat : USHORT { @@ -259,12 +259,11 @@ struct Anchor private: union { USHORT format; /* Format identifier */ - AnchorFormat1 format1[]; - AnchorFormat2 format2[]; - AnchorFormat3 format3[]; + AnchorFormat1 format1[VAR]; + AnchorFormat2 format2[VAR]; + AnchorFormat3 format3[VAR]; } u; }; -ASSERT_SIZE (Anchor, 2); struct AnchorMatrix @@ -287,10 +286,10 @@ struct AnchorMatrix USHORT rows; /* Number of rows */ private: OffsetTo - matrix[]; /* Matrix of offsets to Anchor tables-- + matrix[VAR]; /* Matrix of offsets to Anchor tables-- * from beginning of AnchorMatrix table */ }; -ASSERT_SIZE (AnchorMatrix, 2); +ASSERT_SIZE_VAR (AnchorMatrix, 2, OffsetTo); struct MarkRecord @@ -389,7 +388,7 @@ struct SinglePosFormat1 * value(s)--applied to all glyphs in * the Coverage table */ }; -ASSERT_SIZE (SinglePosFormat1, 6); +ASSERT_SIZE_VAR (SinglePosFormat1, 6, ValueRecord); struct SinglePosFormat2 { @@ -431,7 +430,7 @@ struct SinglePosFormat2 ValueRecord values; /* Array of ValueRecords--positioning * values applied to glyphs */ }; -ASSERT_SIZE (SinglePosFormat2, 8); +ASSERT_SIZE_VAR (SinglePosFormat2, 8, ValueRecord); struct SinglePos { @@ -461,11 +460,10 @@ struct SinglePos private: union { USHORT format; /* Format identifier */ - SinglePosFormat1 format1[]; - SinglePosFormat2 format2[]; + SinglePosFormat1 format1[VAR]; + SinglePosFormat2 format2[VAR]; } u; }; -ASSERT_SIZE (SinglePos, 2); struct PairValueRecord @@ -479,7 +477,7 @@ struct PairValueRecord ValueRecord values; /* Positioning data for the first glyph * followed by for second glyph */ }; -ASSERT_SIZE (PairValueRecord, 2); +ASSERT_SIZE_VAR (PairValueRecord, 2, ValueRecord); struct PairSet { @@ -495,10 +493,10 @@ struct PairSet private: USHORT len; /* Number of PairValueRecords */ PairValueRecord - array[]; /* Array of PairValueRecords--ordered + array[VAR]; /* Array of PairValueRecords--ordered * by GlyphID of the second glyph */ }; -ASSERT_SIZE (PairSet, 2); +ASSERT_SIZE_VAR (PairSet, 2, PairValueRecord); struct PairPosFormat1 { @@ -654,7 +652,7 @@ struct PairPosFormat2 * class1-major, class2-minor, * Each entry has value1 and value2 */ }; -ASSERT_SIZE (PairPosFormat2, 16); +ASSERT_SIZE_VAR (PairPosFormat2, 16, ValueRecord); struct PairPos { @@ -684,11 +682,10 @@ struct PairPos private: union { USHORT format; /* Format identifier */ - PairPosFormat1 format1[]; - PairPosFormat2 format2[]; + PairPosFormat1 format1[VAR]; + PairPosFormat2 format2[VAR]; } u; }; -ASSERT_SIZE (PairPos, 2); struct EntryExitRecord @@ -931,17 +928,15 @@ struct CursivePos private: union { USHORT format; /* Format identifier */ - CursivePosFormat1 format1[]; + CursivePosFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (CursivePos, 2); typedef AnchorMatrix BaseArray; /* base-major-- * in order of BaseCoverage Index--, * mark-minor-- * ordered by class--zero-based. */ -ASSERT_SIZE (BaseArray, 2); struct MarkBasePosFormat1 { @@ -1027,23 +1022,20 @@ struct MarkBasePos private: union { USHORT format; /* Format identifier */ - MarkBasePosFormat1 format1[]; + MarkBasePosFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (MarkBasePos, 2); typedef AnchorMatrix LigatureAttach; /* component-major-- * in order of writing direction--, * mark-minor-- * ordered by class--zero-based. */ -ASSERT_SIZE (LigatureAttach, 2); typedef OffsetListOf LigatureArray; /* Array of LigatureAttach * tables ordered by * LigatureCoverage Index */ -ASSERT_SIZE (LigatureArray, 2); struct MarkLigPosFormat1 { @@ -1152,17 +1144,15 @@ struct MarkLigPos private: union { USHORT format; /* Format identifier */ - MarkLigPosFormat1 format1[]; + MarkLigPosFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (MarkLigPos, 2); typedef AnchorMatrix Mark2Array; /* mark2-major-- * in order of Mark2Coverage Index--, * mark1-minor-- * ordered by class--zero-based. */ -ASSERT_SIZE (Mark2Array, 2); struct MarkMarkPosFormat1 { @@ -1253,10 +1243,9 @@ struct MarkMarkPos private: union { USHORT format; /* Format identifier */ - MarkMarkPosFormat1 format1[]; + MarkMarkPosFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (MarkMarkPos, 2); static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index); @@ -1272,7 +1261,6 @@ struct ContextPos : Context return Context::apply (APPLY_ARG, position_lookup); } }; -ASSERT_SIZE (ContextPos, 2); struct ChainContextPos : ChainContext { @@ -1285,7 +1273,6 @@ struct ChainContextPos : ChainContext return ChainContext::apply (APPLY_ARG, position_lookup); } }; -ASSERT_SIZE (ChainContextPos, 2); struct ExtensionPos : Extension @@ -1300,7 +1287,6 @@ struct ExtensionPos : Extension inline bool sanitize (SANITIZE_ARG_DEF); }; -ASSERT_SIZE (ExtensionPos, 2); @@ -1362,18 +1348,17 @@ struct PosLookupSubTable private: union { USHORT format; - SinglePos single[]; - PairPos pair[]; - CursivePos cursive[]; - MarkBasePos markBase[]; - MarkLigPos markLig[]; - MarkMarkPos markMark[]; - ContextPos context[]; - ChainContextPos chainContext[]; - ExtensionPos extension[]; + SinglePos single[VAR]; + PairPos pair[VAR]; + CursivePos cursive[VAR]; + MarkBasePos markBase[VAR]; + MarkLigPos markLig[VAR]; + MarkMarkPos markMark[VAR]; + ContextPos context[VAR]; + ChainContextPos chainContext[VAR]; + ExtensionPos extension[VAR]; } u; }; -ASSERT_SIZE (PosLookupSubTable, 2); struct PosLookup : Lookup @@ -1462,7 +1447,6 @@ struct PosLookup : Lookup return SANITIZE_THIS (list); } }; -ASSERT_SIZE (PosLookup, 6); typedef OffsetListOf PosLookupList; ASSERT_SIZE (PosLookupList, 2); diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index bd29cf74c..dde1cf5ab 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -141,11 +141,10 @@ struct SingleSubst private: union { USHORT format; /* Format identifier */ - SingleSubstFormat1 format1[]; - SingleSubstFormat2 format2[]; + SingleSubstFormat1 format1[VAR]; + SingleSubstFormat2 format2[VAR]; } u; }; -ASSERT_SIZE (SingleSubst, 2); struct Sequence @@ -160,7 +159,7 @@ struct Sequence return false; _hb_buffer_add_output_glyphs (buffer, 1, - substitute.len, (const uint16_t *) substitute.array, + substitute.len, (const uint16_t *) substitute.const_array(), 0xFFFF, 0xFFFF); /* This is a guess only ... */ @@ -249,10 +248,9 @@ struct MultipleSubst private: union { USHORT format; /* Format identifier */ - MultipleSubstFormat1 format1[]; + MultipleSubstFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (MultipleSubst, 2); typedef ArrayOf AlternateSet; /* Array of alternate GlyphIDs--in @@ -345,10 +343,9 @@ struct AlternateSubst private: union { USHORT format; /* Format identifier */ - AlternateSubstFormat1 format1[]; + AlternateSubstFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (AlternateSubst, 2); struct Ligature @@ -531,10 +528,9 @@ struct LigatureSubst private: union { USHORT format; /* Format identifier */ - LigatureSubstFormat1 format1[]; + LigatureSubstFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (LigatureSubst, 2); @@ -551,7 +547,6 @@ struct ContextSubst : Context return Context::apply (APPLY_ARG, substitute_lookup); } }; -ASSERT_SIZE (ContextSubst, 2); struct ChainContextSubst : ChainContext { @@ -564,7 +559,6 @@ struct ChainContextSubst : ChainContext return ChainContext::apply (APPLY_ARG, substitute_lookup); } }; -ASSERT_SIZE (ChainContextSubst, 2); struct ExtensionSubst : Extension @@ -579,7 +573,6 @@ struct ExtensionSubst : Extension inline bool sanitize (SANITIZE_ARG_DEF); }; -ASSERT_SIZE (ExtensionSubst, 2); struct ReverseChainSingleSubstFormat1 @@ -601,10 +594,10 @@ struct ReverseChainSingleSubstFormat1 const ArrayOf &substitute = CONST_NEXT (ArrayOf, lookahead); if (match_backtrack (APPLY_ARG, - backtrack.len, (USHORT *) backtrack.array, + backtrack.len, (USHORT *) backtrack.const_array(), match_coverage, DECONST_CHARP(this)) && match_lookahead (APPLY_ARG, - lookahead.len, (USHORT *) lookahead.array, + lookahead.len, (USHORT *) lookahead.const_array(), match_coverage, DECONST_CHARP(this), 1)) { @@ -672,10 +665,9 @@ struct ReverseChainSingleSubst private: union { USHORT format; /* Format identifier */ - ReverseChainSingleSubstFormat1 format1[]; + ReverseChainSingleSubstFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (ReverseChainSingleSubst, 2); @@ -733,17 +725,16 @@ struct SubstLookupSubTable private: union { USHORT format; - SingleSubst single[]; - MultipleSubst multiple[]; - AlternateSubst alternate[]; - LigatureSubst ligature[]; - ContextSubst context[]; - ChainContextSubst chainContext[]; - ExtensionSubst extension[]; - ReverseChainSingleSubst reverseChainContextSingle[]; + SingleSubst single[VAR]; + MultipleSubst multiple[VAR]; + AlternateSubst alternate[VAR]; + LigatureSubst ligature[VAR]; + ContextSubst context[VAR]; + ChainContextSubst chainContext[VAR]; + ExtensionSubst extension[VAR]; + ReverseChainSingleSubst reverseChainContextSingle[VAR]; } u; }; -ASSERT_SIZE (SubstLookupSubTable, 2); struct SubstLookup : Lookup @@ -846,7 +837,6 @@ struct SubstLookup : Lookup return SANITIZE_THIS (list); } }; -ASSERT_SIZE (SubstLookup, 6); typedef OffsetListOf SubstLookupList; ASSERT_SIZE (SubstLookupList, 2); diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 8b9b1cd43..91703da31 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -307,7 +307,7 @@ struct Rule public: inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); - if (!SANITIZE_SELF ()) return false; + if (!(SANITIZE (inputCount) && SANITIZE (lookupCount))) return false; return SANITIZE_MEM (input, sizeof (input[0]) * inputCount + sizeof (lookupRecordX[0]) * lookupCount); @@ -318,12 +318,12 @@ struct Rule * glyph sequence--includes the first * glyph */ USHORT lookupCount; /* Number of LookupRecords */ - USHORT input[]; /* Array of match inputs--start with + USHORT input[VAR]; /* Array of match inputs--start with * second glyph */ - LookupRecord lookupRecordX[]; /* Array of LookupRecords--in + LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in * design order */ }; -ASSERT_SIZE (Rule, 4); +ASSERT_SIZE_VAR2 (Rule, 4, USHORT, LookupRecord); struct RuleSet { @@ -473,12 +473,12 @@ struct ContextFormat3 * sequence */ USHORT lookupCount; /* Number of LookupRecords */ OffsetTo - coverage[]; /* Array of offsets to Coverage + coverage[VAR]; /* Array of offsets to Coverage * table in glyph sequence order */ - LookupRecord lookupRecordX[]; /* Array of LookupRecords--in + LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in * design order */ }; -ASSERT_SIZE (ContextFormat3, 6); +ASSERT_SIZE_VAR2 (ContextFormat3, 6, OffsetTo, LookupRecord); struct Context { @@ -508,12 +508,11 @@ struct Context private: union { USHORT format; /* Format identifier */ - ContextFormat1 format1[]; - ContextFormat2 format2[]; - ContextFormat3 format3[]; + ContextFormat1 format1[VAR]; + ContextFormat2 format2[VAR]; + ContextFormat3 format3[VAR]; } u; }; -ASSERT_SIZE (Context, 2); /* Chaining Contextual lookups */ @@ -572,10 +571,10 @@ struct ChainRule const ArrayOf &lookahead = CONST_NEXT (ArrayOf, input); const ArrayOf &lookup = CONST_NEXT (ArrayOf, lookahead); return chain_context_lookup (APPLY_ARG, - backtrack.len, backtrack.array, - input.len, input.array, - lookahead.len, lookahead.array, - lookup.len, lookup.array, + backtrack.len, backtrack.const_array(), + input.len, input.const_array(), + lookahead.len, lookahead.const_array(), + lookup.len, lookup.const_array(), lookup_context); return false; } @@ -754,10 +753,10 @@ struct ChainContextFormat3 {DECONST_CHARP(this), DECONST_CHARP(this), DECONST_CHARP(this)} }; return chain_context_lookup (APPLY_ARG, - backtrack.len, (USHORT *) backtrack.array, - input.len, (USHORT *) input.array + 1, - lookahead.len, (USHORT *) lookahead.array, - lookup.len, lookup.array, + backtrack.len, (const USHORT *) backtrack.const_array(), + input.len, (const USHORT *) input.const_array() + 1, + lookahead.len, (const USHORT *) lookahead.const_array(), + lookup.len, lookup.const_array(), lookup_context); return false; } @@ -821,12 +820,11 @@ struct ChainContext private: union { USHORT format; /* Format identifier */ - ChainContextFormat1 format1[]; - ChainContextFormat2 format2[]; - ChainContextFormat3 format3[]; + ChainContextFormat1 format1[VAR]; + ChainContextFormat2 format2[VAR]; + ChainContextFormat3 format3[VAR]; } u; }; -ASSERT_SIZE (ChainContext, 2); struct ExtensionFormat1 @@ -889,10 +887,9 @@ struct Extension private: union { USHORT format; /* Format identifier */ - ExtensionFormat1 format1[]; + ExtensionFormat1 format1[VAR]; } u; }; -ASSERT_SIZE (Extension, 2); /* diff --git a/src/hb-private.h b/src/hb-private.h index f040ae520..fcebe5638 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -139,6 +139,11 @@ typedef int hb_mutex_t; #define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size)) +#define VAR 1 /* Size signifying variable-sized array */ +#define ASSERT_SIZE_VAR(_type, _size, _var_type) \ + ASSERT_STATIC (sizeof (_type) == (_size) + VAR * sizeof (_var_type)) +#define ASSERT_SIZE_VAR2(_type, _size, _var_type1, _var_type2) \ + ASSERT_STATIC (sizeof (_type) == (_size) + VAR * sizeof (_var_type1) + VAR * sizeof (_var_type2)) #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #define _HB_BOOLEAN_EXPR(expr) \