提交 d3480ba3 编写于 作者: B Behdad Esfahbod

Don't use zero-sized arrays

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