From b157617644d1e38f680163889d1dc2e2f64d9ba3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 6 May 2010 14:48:27 -0400 Subject: [PATCH] Remove the last of SANITIZE macros: SANITIZE_SELF --- src/hb-open-file-private.hh | 4 ++-- src/hb-open-type-private.hh | 21 ++++++++++++--------- src/hb-ot-layout-common-private.hh | 16 ++++++++-------- src/hb-ot-layout-gdef-private.hh | 6 +++--- src/hb-ot-layout-gpos-private.hh | 26 +++++++++++++------------- src/hb-ot-layout-gsubgpos-private.hh | 6 +++--- 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index b58e26b..cf75df9 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -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); } diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 82c23c6..82242e9 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -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 + 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 @@ -352,7 +355,7 @@ struct IntType inline bool operator != (const IntType &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 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 (*CharP(base), offset); @@ -450,7 +453,7 @@ struct GenericOffsetTo : OffsetType template 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 (*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); } diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 0ff3dd6..09a6930 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -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 ()); } diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 76b3ffc..652561c 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -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); } diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 95d9353..60ee17e 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -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) diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 9f2ab4a..7777b9c 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -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::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: -- 2.7.4