Remove the last of SANITIZE macros: SANITIZE_SELF

This commit is contained in:
Behdad Esfahbod 2010-05-06 14:48:27 -04:00
parent 4f252fedc7
commit b157617644
6 changed files with 41 additions and 38 deletions

View File

@ -51,7 +51,7 @@ typedef struct TableDirectory
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
Tag tag; /* 4-byte identifier. */
@ -100,7 +100,7 @@ typedef struct OffsetTable
public:
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& context->check_array (tableDir, TableDirectory::get_size (), numTables);
}

View File

@ -202,7 +202,6 @@ struct hb_sanitize_context_t
{
bool overflows = len >= ((unsigned int) -1) / record_size;
if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE)
fprintf (stderr, "SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s\n", \
base,
@ -214,6 +213,12 @@ struct hb_sanitize_context_t
return likely (!overflows && this->check_range (base, record_size * len));
}
template <typename Type>
inline bool check_struct (const Type *obj) const
{
return likely (this->check_range (obj, sizeof (*obj)));
}
inline bool can_edit (const char *base HB_UNUSED, unsigned int len HB_UNUSED)
{
this->edit_count++;
@ -238,8 +243,6 @@ struct hb_sanitize_context_t
};
#define SANITIZE_SELF() likely(context->check_range (this, sizeof (*this)))
/* Template to sanitize an object. */
template <typename Type>
@ -352,7 +355,7 @@ struct IntType
inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private: BEInt<Type, sizeof (Type)> v;
};
@ -414,7 +417,7 @@ struct FixedVersion
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
USHORT major;
@ -441,7 +444,7 @@ struct GenericOffsetTo : OffsetType
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
TRACE_SANITIZE ();
if (!SANITIZE_SELF ()) return false;
if (!context->check_struct (this)) return false;
unsigned int offset = *this;
if (unlikely (!offset)) return true;
Type &obj = StructAtOffset<Type> (*CharP(base), offset);
@ -450,7 +453,7 @@ struct GenericOffsetTo : OffsetType
template <typename T>
inline bool sanitize (hb_sanitize_context_t *context, void *base, T user_data) {
TRACE_SANITIZE ();
if (!SANITIZE_SELF ()) return false;
if (!context->check_struct (this)) return false;
unsigned int offset = *this;
if (unlikely (!offset)) return true;
Type &obj = StructAtOffset<Type> (*CharP(base), offset);
@ -547,7 +550,7 @@ struct GenericArrayOf
private:
inline bool sanitize_shallow (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF()
return context->check_struct (this)
&& context->check_array (this, Type::get_size (), len);
}
@ -615,7 +618,7 @@ struct HeadlessArrayOf
{ return len.get_size () + (len ? len - 1 : 0) * Type::get_size (); }
inline bool sanitize_shallow (hb_sanitize_context_t *context) {
return SANITIZE_SELF()
return context->check_struct (this)
&& context->check_array (this, Type::get_size (), len);
}

View File

@ -55,7 +55,7 @@ struct Record
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& offset.sanitize (context, base);
}
@ -166,7 +166,7 @@ struct LangSys
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& featureIndex.sanitize (context);
}
@ -235,7 +235,7 @@ struct Feature
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& lookupIndex.sanitize (context);
}
@ -287,7 +287,7 @@ struct Lookup
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
/* Real sanitize of the subtables is done by GSUB/GPOS/... */
if (!(SANITIZE_SELF ()
if (!(context->check_struct (this)
&& likely (subTable.sanitize (context)))) return false;
if (unlikely (lookupFlag & LookupFlag::UseMarkFilteringSet))
{
@ -363,7 +363,7 @@ struct CoverageRangeRecord
public:
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -457,7 +457,7 @@ struct ClassDefFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& classValue.sanitize (context);
}
@ -485,7 +485,7 @@ struct ClassRangeRecord
public:
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -598,7 +598,7 @@ struct Device
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF()
return context->check_struct (this)
&& context->check_range (this, this->get_size ());
}

View File

@ -100,7 +100,7 @@ struct CaretValueFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -126,7 +126,7 @@ struct CaretValueFormat2
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -148,7 +148,7 @@ struct CaretValueFormat3
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& deviceTable.sanitize (context, this);
}

View File

@ -220,7 +220,7 @@ struct AnchorFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -251,7 +251,7 @@ struct AnchorFormat2
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private:
@ -282,7 +282,7 @@ struct AnchorFormat3
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& xDeviceTable.sanitize (context, this)
&& yDeviceTable.sanitize (context, this);
}
@ -346,7 +346,7 @@ struct AnchorMatrix
inline bool sanitize (hb_sanitize_context_t *context, unsigned int cols) {
TRACE_SANITIZE ();
if (!SANITIZE_SELF ()) return false;
if (!context->check_struct (this)) return false;
if (unlikely (cols >= ((unsigned int) -1) / rows)) return false;
unsigned int count = rows * cols;
if (!context->check_array (matrix, matrix[0].get_size (), count)) return false;
@ -372,7 +372,7 @@ struct MarkRecord
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& markAnchor.sanitize (context, base);
}
@ -448,7 +448,7 @@ struct SinglePosFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& coverage.sanitize (context, this)
&& valueFormat.sanitize_value (context, CharP(this), values);
}
@ -491,7 +491,7 @@ struct SinglePosFormat2
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& coverage.sanitize (context, this)
&& valueFormat.sanitize_values (context, CharP(this), values, valueCount);
}
@ -563,7 +563,7 @@ struct PairSet
/* Note: Doesn't sanitize the Device entries in the ValueRecord */
inline bool sanitize (hb_sanitize_context_t *context, unsigned int format_len) {
TRACE_SANITIZE ();
if (!SANITIZE_SELF ()) return false;
if (!context->check_struct (this)) return false;
unsigned int count = (1 + format_len) * len;
return context->check_array (array, USHORT::get_size (), count);
}
@ -630,7 +630,7 @@ struct PairPosFormat1
unsigned int len1 = valueFormat1.get_len ();
unsigned int len2 = valueFormat2.get_len ();
if (!(SANITIZE_SELF ()
if (!(context->check_struct (this)
&& coverage.sanitize (context, this)
&& likely (pairSet.sanitize (context, CharP(this), len1 + len2)))) return false;
@ -715,7 +715,7 @@ struct PairPosFormat2
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
if (!(SANITIZE_SELF ()
if (!(context->check_struct (this)
&& coverage.sanitize (context, this)
&& classDef1.sanitize (context, this)
&& classDef2.sanitize (context, this))) return false;
@ -1084,7 +1084,7 @@ struct MarkBasePosFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& markCoverage.sanitize (context, this)
&& baseCoverage.sanitize (context, this)
&& markArray.sanitize (context, this)
@ -1208,7 +1208,7 @@ struct MarkLigPosFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& markCoverage.sanitize (context, this)
&& ligatureCoverage.sanitize (context, this)
&& markArray.sanitize (context, this)
@ -1311,7 +1311,7 @@ struct MarkMarkPosFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ()
return context->check_struct (this)
&& mark1Coverage.sanitize (context, this)
&& mark2Coverage.sanitize (context, this)
&& mark1Array.sanitize (context, this)

View File

@ -176,7 +176,7 @@ struct LookupRecord
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
USHORT sequenceIndex; /* Index into current glyph
@ -443,7 +443,7 @@ struct ContextFormat3
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
if (!SANITIZE_SELF ()) return false;
if (!context->check_struct (this)) return false;
unsigned int count = glyphCount;
if (!context->check_array (coverage, OffsetTo<Coverage>::get_size (), count)) return false;
for (unsigned int i = 0; i < count; i++)
@ -824,7 +824,7 @@ struct ExtensionFormat1
inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE ();
return SANITIZE_SELF ();
return context->check_struct (this);
}
private: