Annotate SANITIZE return values

More to come, for APPLY, CLOSURE, etc.
This commit is contained in:
Behdad Esfahbod 2012-05-11 01:25:34 +02:00
parent 829e814ff3
commit 0ab8c86217
13 changed files with 299 additions and 316 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright © 2007,2008,2009 Red Hat, Inc.
* Copyright © 2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -22,6 +23,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Red Hat Author(s): Behdad Esfahbod
* Google Author(s): Behdad Esfahbod
*/
#ifndef HB_OPEN_FILE_PRIVATE_HH
@ -51,7 +53,7 @@ typedef struct TableRecord
{
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
Tag tag; /* 4-byte identifier. */
@ -100,8 +102,7 @@ typedef struct OffsetTable
public:
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& c->check_array (tables, TableRecord::static_size, numTables);
return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
}
private:
@ -129,7 +130,7 @@ struct TTCHeaderVersion1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return table.sanitize (c, this);
return TRACE_RETURN (table.sanitize (c, this));
}
private:
@ -168,11 +169,11 @@ struct TTCHeader
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!u.header.version.sanitize (c))) return false;
if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false);
switch (u.header.version.major) {
case 2: /* version 2 is compatible with version 1 */
case 1: return u.version1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.version1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -230,14 +231,14 @@ struct OpenTypeFontFile
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!u.tag.sanitize (c))) return false;
if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false);
switch (u.tag) {
case CFFTag: /* All the non-collection tags */
case TrueTag:
case Typ1Tag:
case TrueTypeTag: return u.fontFace.sanitize (c);
case TTCTag: return u.ttcHeader.sanitize (c);
default: return true;
case TrueTypeTag: return TRACE_RETURN (u.fontFace.sanitize (c));
case TTCTag: return TRACE_RETURN (u.ttcHeader.sanitize (c));
default: return TRACE_RETURN (true);
}
}

View File

@ -1,5 +1,6 @@
/*
* Copyright © 2007,2008,2009,2010 Red Hat, Inc.
* Copyright © 2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -22,6 +23,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Red Hat Author(s): Behdad Esfahbod
* Google Author(s): Behdad Esfahbod
*/
#ifndef HB_OPEN_TYPE_PRIVATE_HH
@ -153,7 +155,7 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
#define TRACE_SANITIZE() \
hb_auto_trace_t<HB_DEBUG_SANITIZE, unsigned int> trace (&c->debug_depth, "SANITIZE", this, HB_FUNC, "");
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&c->debug_depth, "SANITIZE", this, HB_FUNC, "");
struct hb_sanitize_context_t
@ -371,7 +373,7 @@ struct IntType
inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; }
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return likely (c->check_struct (this));
return TRACE_RETURN (likely (c->check_struct (this)));
}
protected:
BEInt<Type, sizeof (Type)> v;
@ -401,7 +403,7 @@ struct LONGDATETIME
{
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return likely (c->check_struct (this));
return TRACE_RETURN (likely (c->check_struct (this)));
}
private:
LONG major;
@ -465,7 +467,7 @@ struct FixedVersion
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
USHORT major;
@ -493,20 +495,20 @@ struct GenericOffsetTo : OffsetType
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
if (unlikely (!c->check_struct (this))) return false;
if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false);
unsigned int offset = *this;
if (unlikely (!offset)) return true;
if (unlikely (!offset)) return TRACE_RETURN (true);
Type &obj = StructAtOffset<Type> (base, offset);
return likely (obj.sanitize (c)) || neuter (c);
return TRACE_RETURN (likely (obj.sanitize (c)) || neuter (c));
}
template <typename T>
inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) {
TRACE_SANITIZE ();
if (unlikely (!c->check_struct (this))) return false;
if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false);
unsigned int offset = *this;
if (unlikely (!offset)) return true;
if (unlikely (!offset)) return TRACE_RETURN (true);
Type &obj = StructAtOffset<Type> (base, offset);
return likely (obj.sanitize (c, user_data)) || neuter (c);
return TRACE_RETURN (likely (obj.sanitize (c, user_data)) || neuter (c));
}
private:
@ -558,7 +560,7 @@ struct GenericArrayOf
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!sanitize_shallow (c))) return false;
if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false);
/* Note: for structs that do not reference other structs,
* we do not need to call their sanitize() as we already did
@ -569,33 +571,32 @@ struct GenericArrayOf
*/
(void) (false && array[0].sanitize (c));
return true;
return TRACE_RETURN (true);
}
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
if (unlikely (!sanitize_shallow (c))) return false;
if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false);
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
if (unlikely (!array[i].sanitize (c, base)))
return false;
return true;
return TRACE_RETURN (false);
return TRACE_RETURN (true);
}
template <typename T>
inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) {
TRACE_SANITIZE ();
if (unlikely (!sanitize_shallow (c))) return false;
if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false);
unsigned int count = len;
for (unsigned int i = 0; i < count; i++)
if (unlikely (!array[i].sanitize (c, base, user_data)))
return false;
return true;
return TRACE_RETURN (false);
return TRACE_RETURN (true);
}
private:
inline bool sanitize_shallow (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& c->check_array (this, Type::static_size, len);
return TRACE_RETURN (c->check_struct (this) && c->check_array (this, Type::static_size, len));
}
public:
@ -637,12 +638,12 @@ struct OffsetListOf : OffsetArrayOf<Type>
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return OffsetArrayOf<Type>::sanitize (c, this);
return TRACE_RETURN (OffsetArrayOf<Type>::sanitize (c, this));
}
template <typename T>
inline bool sanitize (hb_sanitize_context_t *c, T user_data) {
TRACE_SANITIZE ();
return OffsetArrayOf<Type>::sanitize (c, this, user_data);
return TRACE_RETURN (OffsetArrayOf<Type>::sanitize (c, this, user_data));
}
};
@ -667,7 +668,7 @@ struct HeadlessArrayOf
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!sanitize_shallow (c))) return false;
if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false);
/* Note: for structs that do not reference other structs,
* we do not need to call their sanitize() as we already did
@ -678,7 +679,7 @@ struct HeadlessArrayOf
*/
(void) (false && array[0].sanitize (c));
return true;
return TRACE_RETURN (true);
}
USHORT len;

View File

@ -1,5 +1,6 @@
/*
* Copyright © 2010 Red Hat, Inc.
* Copyright © 2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -22,6 +23,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Red Hat Author(s): Behdad Esfahbod
* Google Author(s): Behdad Esfahbod
*/
#ifndef HB_OT_HEAD_TABLE_HH
@ -49,7 +51,7 @@ struct head
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this) && likely (version.major == 1);
return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1));
}
private:

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -44,7 +44,7 @@ struct hhea
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this) && likely (version.major == 1);
return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1));
}
private:

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -54,7 +54,7 @@ struct hmtx
TRACE_SANITIZE ();
/* We don't check for anything specific here. The users of the
* struct do all the hard work... */
return true;
return TRACE_RETURN (true);
}
private:

View File

@ -60,8 +60,7 @@ struct Record
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& offset.sanitize (c, base);
return TRACE_RETURN (c->check_struct (this) && offset.sanitize (c, base));
}
Tag tag; /* 4-byte Tag identifier */
@ -115,7 +114,7 @@ struct RecordListOf : RecordArrayOf<Type>
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return RecordArrayOf<Type>::sanitize (c, this);
return TRACE_RETURN (RecordArrayOf<Type>::sanitize (c, this));
}
};
@ -129,7 +128,7 @@ struct RangeRecord
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
inline bool intersects (const hb_set_t *glyphs) const {
@ -188,8 +187,7 @@ struct LangSys
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& featureIndex.sanitize (c);
return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c));
}
Offset lookupOrder; /* = Null (reserved for an offset to a
@ -227,8 +225,7 @@ struct Script
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return defaultLangSys.sanitize (c, this)
&& langSys.sanitize (c, this);
return TRACE_RETURN (defaultLangSys.sanitize (c, this) && langSys.sanitize (c, this));
}
private:
@ -258,8 +255,7 @@ struct Feature
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& lookupIndex.sanitize (c);
return TRACE_RETURN (c->check_struct (this) && lookupIndex.sanitize (c));
}
Offset featureParams; /* Offset to Feature Parameters table (if one
@ -313,14 +309,13 @@ struct Lookup
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
/* Real sanitize of the subtables is done by GSUB/GPOS/... */
if (!(c->check_struct (this)
&& subTable.sanitize (c))) return false;
if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN (false);
if (unlikely (lookupFlag & LookupFlag::UseMarkFilteringSet))
{
USHORT &markFilteringSet = StructAfter<USHORT> (subTable);
if (!markFilteringSet.sanitize (c)) return false;
if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false);
}
return true;
return TRACE_RETURN (true);
}
USHORT lookupType; /* Different enumerations for GSUB and GPOS */
@ -356,7 +351,7 @@ struct CoverageFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return glyphArray.sanitize (c);
return TRACE_RETURN (glyphArray.sanitize (c));
}
inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const {
@ -400,7 +395,7 @@ struct CoverageFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return rangeRecord.sanitize (c);
return TRACE_RETURN (rangeRecord.sanitize (c));
}
inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const {
@ -469,11 +464,11 @@ struct Coverage
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -571,8 +566,7 @@ struct ClassDefFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& classValue.sanitize (c);
return TRACE_RETURN (c->check_struct (this) && classValue.sanitize (c));
}
inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const {
@ -606,7 +600,7 @@ struct ClassDefFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return rangeRecord.sanitize (c);
return TRACE_RETURN (rangeRecord.sanitize (c));
}
inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const {
@ -640,11 +634,11 @@ struct ClassDef
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -724,8 +718,7 @@ struct Device
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& c->check_range (this, this->get_size ());
return TRACE_RETURN (c->check_struct (this) && c->check_range (this, this->get_size ()));
}
private:

View File

@ -1,6 +1,6 @@
/*
* Copyright © 2007,2008,2009 Red Hat, Inc.
* Copyright © 2010,2011 Google, Inc.
* Copyright © 2010,2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -71,8 +71,7 @@ struct AttachList
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& attachPoint.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
}
private:
@ -102,7 +101,7 @@ struct CaretValueFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
private:
@ -128,7 +127,7 @@ struct CaretValueFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
private:
@ -151,8 +150,7 @@ struct CaretValueFormat3
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& deviceTable.sanitize (c, this);
return TRACE_RETURN (c->check_struct (this) && deviceTable.sanitize (c, this));
}
private:
@ -180,12 +178,12 @@ struct CaretValue
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
case 3: return u.format3.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
case 3: return TRACE_RETURN (u.format3.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -221,7 +219,7 @@ struct LigGlyph
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return carets.sanitize (c, this);
return TRACE_RETURN (carets.sanitize (c, this));
}
private:
@ -255,8 +253,7 @@ struct LigCaretList
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& ligGlyph.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
}
private:
@ -278,7 +275,7 @@ struct MarkGlyphSetsFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this));
}
private:
@ -302,10 +299,10 @@ struct MarkGlyphSets
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -365,12 +362,13 @@ struct GDEF
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return version.sanitize (c) && likely (version.major == 1)
&& glyphClassDef.sanitize (c, this)
&& attachList.sanitize (c, this)
&& ligCaretList.sanitize (c, this)
&& markAttachClassDef.sanitize (c, this)
&& (version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
return TRACE_RETURN (version.sanitize (c) &&
likely (version.major == 1) &&
glyphClassDef.sanitize (c, this) &&
attachList.sanitize (c, this) &&
ligCaretList.sanitize (c, this) &&
markAttachClassDef.sanitize (c, this) &&
(version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this)));
}

View File

@ -171,40 +171,39 @@ struct ValueFormat : USHORT
inline bool sanitize_value (hb_sanitize_context_t *c, void *base, Value *values) {
TRACE_SANITIZE ();
return c->check_range (values, get_size ())
&& (!has_device () || sanitize_value_devices (c, base, values));
return TRACE_RETURN (c->check_range (values, get_size ()) && (!has_device () || sanitize_value_devices (c, base, values)));
}
inline bool sanitize_values (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count) {
TRACE_SANITIZE ();
unsigned int len = get_len ();
if (!c->check_array (values, get_size (), count)) return false;
if (!c->check_array (values, get_size (), count)) return TRACE_RETURN (false);
if (!has_device ()) return true;
if (!has_device ()) return TRACE_RETURN (true);
for (unsigned int i = 0; i < count; i++) {
if (!sanitize_value_devices (c, base, values))
return false;
return TRACE_RETURN (false);
values += len;
}
return true;
return TRACE_RETURN (true);
}
/* Just sanitize referenced Device tables. Doesn't check the values themselves. */
inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count, unsigned int stride) {
TRACE_SANITIZE ();
if (!has_device ()) return true;
if (!has_device ()) return TRACE_RETURN (true);
for (unsigned int i = 0; i < count; i++) {
if (!sanitize_value_devices (c, base, values))
return false;
return TRACE_RETURN (false);
values += stride;
}
return true;
return TRACE_RETURN (true);
}
};
@ -223,7 +222,7 @@ struct AnchorFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
private:
@ -255,7 +254,7 @@ struct AnchorFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
private:
@ -286,9 +285,7 @@ struct AnchorFormat3
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& xDeviceTable.sanitize (c, this)
&& yDeviceTable.sanitize (c, this);
return TRACE_RETURN (c->check_struct (this) && xDeviceTable.sanitize (c, this) && yDeviceTable.sanitize (c, this));
}
private:
@ -323,12 +320,12 @@ struct Anchor
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
case 3: return u.format3.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
case 3: return TRACE_RETURN (u.format3.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -353,13 +350,13 @@ struct AnchorMatrix
inline bool sanitize (hb_sanitize_context_t *c, unsigned int cols) {
TRACE_SANITIZE ();
if (!c->check_struct (this)) return false;
if (unlikely (rows > 0 && cols >= ((unsigned int) -1) / rows)) return false;
if (!c->check_struct (this)) return TRACE_RETURN (false);
if (unlikely (rows > 0 && cols >= ((unsigned int) -1) / rows)) return TRACE_RETURN (false);
unsigned int count = rows * cols;
if (!c->check_array (matrix, matrix[0].static_size, count)) return false;
if (!c->check_array (matrix, matrix[0].static_size, count)) return TRACE_RETURN (false);
for (unsigned int i = 0; i < count; i++)
if (!matrix[i].sanitize (c, this)) return false;
return true;
if (!matrix[i].sanitize (c, this)) return TRACE_RETURN (false);
return TRACE_RETURN (true);
}
USHORT rows; /* Number of rows */
@ -378,8 +375,7 @@ struct MarkRecord
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& markAnchor.sanitize (c, base);
return TRACE_RETURN (c->check_struct (this) && markAnchor.sanitize (c, base));
}
private:
@ -421,7 +417,7 @@ struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage orde
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return ArrayOf<MarkRecord>::sanitize (c, this);
return TRACE_RETURN (ArrayOf<MarkRecord>::sanitize (c, this));
}
};
@ -449,9 +445,7 @@ struct SinglePosFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& coverage.sanitize (c, this)
&& valueFormat.sanitize_value (c, this, values);
return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_value (c, this, values));
}
private:
@ -493,9 +487,7 @@ struct SinglePosFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& coverage.sanitize (c, this)
&& valueFormat.sanitize_values (c, this, values, valueCount);
return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_values (c, this, values, valueCount));
}
private:
@ -529,11 +521,11 @@ struct SinglePos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -604,12 +596,12 @@ struct PairSet
inline bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) {
TRACE_SANITIZE ();
if (!(c->check_struct (this)
&& c->check_array (array, USHORT::static_size * closure->stride, len))) return false;
&& c->check_array (array, USHORT::static_size * closure->stride, len))) return TRACE_RETURN (false);
unsigned int count = len;
PairValueRecord *record = CastP<PairValueRecord> (array);
return closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride)
&& closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride);
return TRACE_RETURN (closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride)
&& closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride));
}
private:
@ -654,9 +646,7 @@ struct PairPosFormat1
1 + len1 + len2
};
return c->check_struct (this)
&& coverage.sanitize (c, this)
&& pairSet.sanitize (c, this, &closure);
return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && pairSet.sanitize (c, this, &closure));
}
private:
@ -723,16 +713,16 @@ struct PairPosFormat2
if (!(c->check_struct (this)
&& coverage.sanitize (c, this)
&& classDef1.sanitize (c, this)
&& classDef2.sanitize (c, this))) return false;
&& classDef2.sanitize (c, this))) return TRACE_RETURN (false);
unsigned int len1 = valueFormat1.get_len ();
unsigned int len2 = valueFormat2.get_len ();
unsigned int stride = len1 + len2;
unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
return c->check_array (values, record_size, count) &&
valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride);
return TRACE_RETURN (c->check_array (values, record_size, count) &&
valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
}
private:
@ -782,11 +772,11 @@ struct PairPos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -805,8 +795,7 @@ struct EntryExitRecord
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
return entryAnchor.sanitize (c, base)
&& exitAnchor.sanitize (c, base);
return TRACE_RETURN (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base));
}
private:
@ -916,8 +905,7 @@ struct CursivePosFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& entryExitRecord.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && entryExitRecord.sanitize (c, this));
}
private:
@ -948,10 +936,10 @@ struct CursivePos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -999,11 +987,8 @@ struct MarkBasePosFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& markCoverage.sanitize (c, this)
&& baseCoverage.sanitize (c, this)
&& markArray.sanitize (c, this)
&& baseArray.sanitize (c, this, (unsigned int) classCount);
return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && baseCoverage.sanitize (c, this) &&
markArray.sanitize (c, this) && baseArray.sanitize (c, this, (unsigned int) classCount));
}
private:
@ -1041,10 +1026,10 @@ struct MarkBasePos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -1121,11 +1106,8 @@ struct MarkLigPosFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& markCoverage.sanitize (c, this)
&& ligatureCoverage.sanitize (c, this)
&& markArray.sanitize (c, this)
&& ligatureArray.sanitize (c, this, (unsigned int) classCount);
return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && ligatureCoverage.sanitize (c, this) &&
markArray.sanitize (c, this) && ligatureArray.sanitize (c, this, (unsigned int) classCount));
}
private:
@ -1164,10 +1146,10 @@ struct MarkLigPos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -1224,11 +1206,9 @@ struct MarkMarkPosFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this)
&& mark1Coverage.sanitize (c, this)
&& mark2Coverage.sanitize (c, this)
&& mark1Array.sanitize (c, this)
&& mark2Array.sanitize (c, this, (unsigned int) classCount);
return TRACE_RETURN (c->check_struct (this) && mark1Coverage.sanitize (c, this) &&
mark2Coverage.sanitize (c, this) && mark1Array.sanitize (c, this)
&& mark2Array.sanitize (c, this, (unsigned int) classCount));
}
private:
@ -1268,10 +1248,10 @@ struct MarkMarkPos
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -1363,23 +1343,23 @@ struct PosLookupSubTable
case Context: return u.c.apply (c);
case ChainContext: return u.chainContext.apply (c);
case Extension: return u.extension.apply (c);
default:return false;
default: return false;
}
}
inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) {
TRACE_SANITIZE ();
switch (lookup_type) {
case Single: return u.single.sanitize (c);
case Pair: return u.pair.sanitize (c);
case Cursive: return u.cursive.sanitize (c);
case MarkBase: return u.markBase.sanitize (c);
case MarkLig: return u.markLig.sanitize (c);
case MarkMark: return u.markMark.sanitize (c);
case Context: return u.c.sanitize (c);
case ChainContext: return u.chainContext.sanitize (c);
case Extension: return u.extension.sanitize (c);
default:return true;
case Single: return TRACE_RETURN (u.single.sanitize (c));
case Pair: return TRACE_RETURN (u.pair.sanitize (c));
case Cursive: return TRACE_RETURN (u.cursive.sanitize (c));
case MarkBase: return TRACE_RETURN (u.markBase.sanitize (c));
case MarkLig: return TRACE_RETURN (u.markLig.sanitize (c));
case MarkMark: return TRACE_RETURN (u.markMark.sanitize (c));
case Context: return TRACE_RETURN (u.c.sanitize (c));
case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c));
case Extension: return TRACE_RETURN (u.extension.sanitize (c));
default: return TRACE_RETURN (true);
}
}
@ -1443,9 +1423,9 @@ struct PosLookup : Lookup
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!Lookup::sanitize (c))) return false;
if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false);
OffsetArrayOf<PosLookupSubTable> &list = CastR<OffsetArrayOf<PosLookupSubTable> > (subTable);
return list.sanitize (c, this, get_type ());
return TRACE_RETURN (list.sanitize (c, this, get_type ()));
}
};
@ -1470,9 +1450,9 @@ struct GPOS : GSUBGPOS
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!GSUBGPOS::sanitize (c))) return false;
if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false);
OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList);
return list.sanitize (c, this);
return TRACE_RETURN (list.sanitize (c, this));
}
public:
DEFINE_SIZE_STATIC (10);
@ -1564,10 +1544,10 @@ inline bool ExtensionPos::apply (hb_apply_context_t *c) const
inline bool ExtensionPos::sanitize (hb_sanitize_context_t *c)
{
TRACE_SANITIZE ();
if (unlikely (!Extension::sanitize (c))) return false;
if (unlikely (!Extension::sanitize (c))) return TRACE_RETURN (false);
unsigned int offset = get_offset ();
if (unlikely (!offset)) return true;
return StructAtOffset<PosLookupSubTable> (this, offset).sanitize (c, get_type ());
if (unlikely (!offset)) return TRACE_RETURN (true);
return TRACE_RETURN (StructAtOffset<PosLookupSubTable> (this, offset).sanitize (c, get_type ()));
}
static inline bool position_lookup (hb_apply_context_t *c, unsigned int lookup_index)

View File

@ -73,8 +73,7 @@ struct SingleSubstFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& deltaGlyphID.sanitize (c);
return TRACE_RETURN (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c));
}
private:
@ -128,8 +127,7 @@ struct SingleSubstFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& substitute.sanitize (c);
return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c));
}
private:
@ -181,11 +179,11 @@ struct SingleSubst
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -228,7 +226,7 @@ struct Sequence
public:
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return substitute.sanitize (c);
return TRACE_RETURN (substitute.sanitize (c));
}
private:
@ -272,8 +270,7 @@ struct MultipleSubstFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& sequence.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && sequence.sanitize (c, this));
}
private:
@ -322,10 +319,10 @@ struct MultipleSubst
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -398,8 +395,7 @@ struct AlternateSubstFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& alternateSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && alternateSet.sanitize (c, this));
}
private:
@ -448,10 +444,10 @@ struct AlternateSubst
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -552,8 +548,7 @@ struct Ligature
public:
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return ligGlyph.sanitize (c)
&& component.sanitize (c);
return TRACE_RETURN (ligGlyph.sanitize (c) && component.sanitize (c));
}
private:
@ -609,7 +604,7 @@ struct LigatureSet
public:
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return ligature.sanitize (c, this);
return TRACE_RETURN (ligature.sanitize (c, this));
}
private:
@ -658,8 +653,7 @@ struct LigatureSubstFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& ligatureSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this));
}
private:
@ -708,10 +702,10 @@ struct LigatureSubst
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -852,14 +846,13 @@ struct ReverseChainSingleSubstFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!(coverage.sanitize (c, this)
&& backtrack.sanitize (c, this)))
return false;
if (!(coverage.sanitize (c, this) && backtrack.sanitize (c, this)))
return TRACE_RETURN (false);
OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
if (!lookahead.sanitize (c, this))
return false;
return TRACE_RETURN (false);
ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
return substitute.sanitize (c);
return TRACE_RETURN (substitute.sanitize (c));
}
private:
@ -908,10 +901,10 @@ struct ReverseChainSingleSubst
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -968,7 +961,7 @@ struct SubstLookupSubTable
case Multiple: return u.multiple.would_apply (glyph_id);
case Alternate: return u.alternate.would_apply (glyph_id);
case Extension: return u.extension.would_apply (glyph_id);
default:return false;
default: return false;
}
}
inline bool would_apply (hb_codepoint_t first,
@ -978,7 +971,7 @@ struct SubstLookupSubTable
switch (lookup_type) {
case Ligature: return u.ligature.would_apply (first, second);
case Extension: return u.extension.would_apply (first, second);
default:return false;
default: return false;
}
}
@ -994,22 +987,22 @@ struct SubstLookupSubTable
case ChainContext: return u.chainContext.apply (c);
case Extension: return u.extension.apply (c);
case ReverseChainSingle: return u.reverseChainContextSingle.apply (c);
default:return false;
default: return false;
}
}
inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) {
TRACE_SANITIZE ();
switch (lookup_type) {
case Single: return u.single.sanitize (c);
case Multiple: return u.multiple.sanitize (c);
case Alternate: return u.alternate.sanitize (c);
case Ligature: return u.ligature.sanitize (c);
case Context: return u.c.sanitize (c);
case ChainContext: return u.chainContext.sanitize (c);
case Extension: return u.extension.sanitize (c);
case ReverseChainSingle: return u.reverseChainContextSingle.sanitize (c);
default:return true;
case Single: return TRACE_RETURN (u.single.sanitize (c));
case Multiple: return TRACE_RETURN (u.multiple.sanitize (c));
case Alternate: return TRACE_RETURN (u.alternate.sanitize (c));
case Ligature: return TRACE_RETURN (u.ligature.sanitize (c));
case Context: return TRACE_RETURN (u.c.sanitize (c));
case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c));
case Extension: return TRACE_RETURN (u.extension.sanitize (c));
case ReverseChainSingle: return TRACE_RETURN (u.reverseChainContextSingle.sanitize (c));
default: return TRACE_RETURN (true);
}
}
@ -1147,9 +1140,9 @@ struct SubstLookup : Lookup
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!Lookup::sanitize (c))) return false;
if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false);
OffsetArrayOf<SubstLookupSubTable> &list = CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable);
return list.sanitize (c, this, get_type ());
return TRACE_RETURN (list.sanitize (c, this, get_type ()));
}
};
@ -1178,9 +1171,9 @@ struct GSUB : GSUBGPOS
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (unlikely (!GSUBGPOS::sanitize (c))) return false;
if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false);
OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList);
return list.sanitize (c, this);
return TRACE_RETURN (list.sanitize (c, this));
}
public:
DEFINE_SIZE_STATIC (10);
@ -1230,10 +1223,10 @@ inline bool ExtensionSubst::apply (hb_apply_context_t *c) const
inline bool ExtensionSubst::sanitize (hb_sanitize_context_t *c)
{
TRACE_SANITIZE ();
if (unlikely (!Extension::sanitize (c))) return false;
if (unlikely (!Extension::sanitize (c))) return TRACE_RETURN (false);
unsigned int offset = get_offset ();
if (unlikely (!offset)) return true;
return StructAtOffset<SubstLookupSubTable> (this, offset).sanitize (c, get_type ());
if (unlikely (!offset)) return TRACE_RETURN (true);
return TRACE_RETURN (StructAtOffset<SubstLookupSubTable> (this, offset).sanitize (c, get_type ()));
}
inline bool ExtensionSubst::is_reverse (void) const

View File

@ -69,7 +69,7 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
#endif
#define TRACE_CLOSURE() \
hb_auto_trace_t<HB_DEBUG_CLOSURE, unsigned int> trace (&c->debug_depth, "CLOSURE", this, HB_FUNC, "");
hb_auto_trace_t<HB_DEBUG_CLOSURE> trace (&c->debug_depth, "CLOSURE", this, HB_FUNC, "");
@ -96,7 +96,7 @@ struct hb_closure_context_t
#endif
#define TRACE_APPLY() \
hb_auto_trace_t<HB_DEBUG_APPLY, unsigned int> trace (&c->debug_depth, "APPLY", this, HB_FUNC, "");
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, HB_FUNC, "");
@ -381,7 +381,7 @@ struct LookupRecord
{
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
USHORT sequenceIndex; /* Index into current glyph
@ -583,7 +583,7 @@ struct RuleSet
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return rule.sanitize (c, this);
return TRACE_RETURN (rule.sanitize (c, this));
}
private:
@ -637,8 +637,7 @@ struct ContextFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& ruleSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
}
private:
@ -700,9 +699,7 @@ struct ContextFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& classDef.sanitize (c, this)
&& ruleSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
}
private:
@ -764,13 +761,13 @@ struct ContextFormat3
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!c->check_struct (this)) return false;
if (!c->check_struct (this)) return TRACE_RETURN (false);
unsigned int count = glyphCount;
if (!c->check_array (coverage, coverage[0].static_size, count)) return false;
if (!c->check_array (coverage, coverage[0].static_size, count)) return TRACE_RETURN (false);
for (unsigned int i = 0; i < count; i++)
if (!coverage[i].sanitize (c, this)) return false;
if (!coverage[i].sanitize (c, this)) return TRACE_RETURN (false);
LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count);
return c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount);
return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
}
private:
@ -815,12 +812,12 @@ struct Context
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
case 3: return u.format3.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
case 3: return TRACE_RETURN (u.format3.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -945,13 +942,13 @@ struct ChainRule
public:
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!backtrack.sanitize (c)) return false;
if (!backtrack.sanitize (c)) return TRACE_RETURN (false);
HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
if (!input.sanitize (c)) return false;
if (!input.sanitize (c)) return TRACE_RETURN (false);
ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
if (!lookahead.sanitize (c)) return false;
if (!lookahead.sanitize (c)) return TRACE_RETURN (false);
ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
return lookup.sanitize (c);
return TRACE_RETURN (lookup.sanitize (c));
}
private:
@ -997,7 +994,7 @@ struct ChainRuleSet
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return rule.sanitize (c, this);
return TRACE_RETURN (rule.sanitize (c, this));
}
private:
@ -1049,8 +1046,7 @@ struct ChainContextFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& ruleSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
}
private:
@ -1120,11 +1116,9 @@ struct ChainContextFormat2
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return coverage.sanitize (c, this)
&& backtrackClassDef.sanitize (c, this)
&& inputClassDef.sanitize (c, this)
&& lookaheadClassDef.sanitize (c, this)
&& ruleSet.sanitize (c, this);
return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) &&
inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) &&
ruleSet.sanitize (c, this));
}
private:
@ -1204,13 +1198,13 @@ struct ChainContextFormat3
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!backtrack.sanitize (c, this)) return false;
if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false);
OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
if (!input.sanitize (c, this)) return false;
if (!input.sanitize (c, this)) return TRACE_RETURN (false);
OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
if (!lookahead.sanitize (c, this)) return false;
if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false);
ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
return lookup.sanitize (c);
return TRACE_RETURN (lookup.sanitize (c));
}
private:
@ -1262,12 +1256,12 @@ struct ChainContext
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
case 2: return u.format2.sanitize (c);
case 3: return u.format3.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
case 2: return TRACE_RETURN (u.format2.sanitize (c));
case 3: return TRACE_RETURN (u.format3.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -1291,7 +1285,7 @@ struct ExtensionFormat1
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this);
return TRACE_RETURN (c->check_struct (this));
}
private:
@ -1324,10 +1318,10 @@ struct Extension
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return false;
if (!u.format.sanitize (c)) return TRACE_RETURN (false);
switch (u.format) {
case 1: return u.format1.sanitize (c);
default:return true;
case 1: return TRACE_RETURN (u.format1.sanitize (c));
default:return TRACE_RETURN (true);
}
}
@ -1381,10 +1375,10 @@ struct GSUBGPOS
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return version.sanitize (c) && likely (version.major == 1)
&& scriptList.sanitize (c, this)
&& featureList.sanitize (c, this)
&& lookupList.sanitize (c, this);
return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) &&
scriptList.sanitize (c, this) &&
featureList.sanitize (c, this) &&
lookupList.sanitize (c, this));
}
protected:

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -47,9 +47,8 @@ struct maxp
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this) &&
likely (version.major == 1 ||
(version.major == 0 && version.minor == 0x5000));
return TRACE_RETURN (c->check_struct (this) &&
likely (version.major == 1 || (version.major == 0 && version.minor == 0x5000)));
}
/* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -57,8 +57,7 @@ struct NameRecord
inline bool sanitize (hb_sanitize_context_t *c, void *base) {
TRACE_SANITIZE ();
/* We can check from base all the way up to the end of string... */
return c->check_struct (this) &&
c->check_range ((char *) base, (unsigned int) length + offset);
return TRACE_RETURN (c->check_struct (this) && c->check_range ((char *) base, (unsigned int) length + offset));
}
USHORT platformID; /* Platform ID. */
@ -102,16 +101,16 @@ struct name
char *string_pool = (char *) this + stringOffset;
unsigned int _count = count;
for (unsigned int i = 0; i < _count; i++)
if (!nameRecord[i].sanitize (c, string_pool)) return false;
return true;
if (!nameRecord[i].sanitize (c, string_pool)) return TRACE_RETURN (false);
return TRACE_RETURN (true);
}
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return c->check_struct (this) &&
likely (format == 0 || format == 1) &&
c->check_array (nameRecord, nameRecord[0].static_size, count) &&
sanitize_records (c);
return TRACE_RETURN (c->check_struct (this) &&
likely (format == 0 || format == 1) &&
c->check_array (nameRecord, nameRecord[0].static_size, count) &&
sanitize_records (c));
}
/* We only implement format 0 for now. */

View File

@ -1,6 +1,6 @@
/*
* Copyright © 2007,2008,2009 Red Hat, Inc.
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@ -519,7 +519,7 @@ _hb_debug_msg_va (const char *what,
fprintf (stderr, "%-10s", what ? what : "");
if (obj)
fprintf (stderr, "(%p) ", obj);
fprintf (stderr, "(%0*x) ", (unsigned int) (2 * sizeof (void *)), (unsigned long) obj);
else
fprintf (stderr, " %*s ", (unsigned int) (2 * sizeof (void *)), "");
@ -601,14 +601,14 @@ _hb_debug_msg<0> (const char *what,
* Trace
*/
template <int max_level, typename T>
template <int max_level>
struct hb_auto_trace_t {
explicit inline hb_auto_trace_t (unsigned int *plevel_,
const char *what,
const void *obj,
const char *func,
const char *message,
...) : plevel(plevel_)
...) : plevel(plevel_), returned (false)
{
if (plevel) ++*plevel;
@ -617,26 +617,49 @@ struct hb_auto_trace_t {
_hb_debug_msg_va<max_level> (what, obj, func, TRUE, plevel ? *plevel : 0, +1, message, ap);
va_end (ap);
}
~hb_auto_trace_t (void)
inline ~hb_auto_trace_t (void)
{
_hb_debug_msg<max_level> (NULL, NULL, NULL, TRUE, plevel ? *plevel : 1, -1, " ");
if (unlikely (!returned)) {
fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report. Level was %d.\n", plevel ? *plevel : -1);
_hb_debug_msg<max_level> (NULL, NULL, NULL, TRUE, plevel ? *plevel : 1, -1, " ");
return;
}
if (plevel) --*plevel;
}
inline bool ret (bool v)
{
if (unlikely (returned)) {
fprintf (stderr, "OUCH, double calls to TRACE_RETURN. This is a bug, please report.\n");
return v;
}
_hb_debug_msg<max_level> (NULL, NULL, NULL, TRUE, plevel ? *plevel : 1, -1, "return %s", v ? "true" : "false");
if (plevel) --*plevel;
plevel = NULL;
returned = true;
return v;
}
private:
unsigned int *plevel;
bool returned;
};
template <typename T> /* Optimize when tracing is disabled */
struct hb_auto_trace_t<0, T> {
template <> /* Optimize when tracing is disabled */
struct hb_auto_trace_t<0> {
explicit inline hb_auto_trace_t (unsigned int *plevel_,
const char *what,
const void *obj,
const char *func,
const char *message,
...) {}
template <typename T>
inline T ret (T v) { return v; }
};
#define TRACE_RETURN(RET) trace.ret (RET)
/* Misc */