[HarfBuzz] harfbuzz-ng: Branch 'master' - 7 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu May 6 11:49:52 PDT 2010


 src/hb-open-file-private.hh          |   12 +-
 src/hb-open-type-private.hh          |   51 +++++------
 src/hb-ot-layout-common-private.hh   |   42 ++++-----
 src/hb-ot-layout-gdef-private.hh     |   36 ++++----
 src/hb-ot-layout-gpos-private.hh     |  154 ++++++++++++++++++-----------------
 src/hb-ot-layout-gsub-private.hh     |   57 ++++++------
 src/hb-ot-layout-gsubgpos-private.hh |   82 +++++++++---------
 7 files changed, 218 insertions(+), 216 deletions(-)

New commits:
commit b157617644d1e38f680163889d1dc2e2f64d9ba3
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 14:48:27 2010 -0400

    Remove the last of SANITIZE macros: SANITIZE_SELF

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 <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);
   }
 
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<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:
commit 4f252fedc7136c66a9d7fbcb2978581986da6227
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 13:30:23 2010 -0400

    Remove SANITIZE macro

diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh
index 4e4494d..b58e26b 100644
--- a/src/hb-open-file-private.hh
+++ b/src/hb-open-file-private.hh
@@ -165,7 +165,7 @@ struct TTCHeader
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.header.version)) return false;
+    if (!u.header.version.sanitize (context)) return false;
     switch (u.header.version) {
     case 2: /* version 2 is compatible with version 1 */
     case 1: return u.version1->sanitize (context);
@@ -227,7 +227,7 @@ struct OpenTypeFontFile
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.tag)) return false;
+    if (!u.tag.sanitize (context)) return false;
     switch (u.tag) {
     case CFFTag:	/* All the non-collection tags */
     case TrueTag:
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 499754f..82c23c6 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -238,8 +238,6 @@ struct hb_sanitize_context_t
 };
 
 
-#define SANITIZE(X) likely ((X).sanitize (context))
-
 #define SANITIZE_SELF() likely(context->check_range (this, sizeof (*this)))
 
 
@@ -522,7 +520,7 @@ struct GenericArrayOf
      * other structs. */
     unsigned int count = len;
     for (unsigned int i = 0; i < count; i++)
-      if (!SANITIZE (array()[i]))
+      if (array()[i].sanitize (context))
         return false;
     return true;
   }
@@ -635,7 +633,7 @@ struct HeadlessArrayOf
     unsigned int count = len ? len - 1 : 0;
     Type *a = array();
     for (unsigned int i = 0; i < count; i++)
-      if (!SANITIZE (a[i]))
+      if (!a[i].sanitize (context))
         return false;
     return true;
   }
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 1a4be0f..0ff3dd6 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -167,7 +167,7 @@ struct LangSys
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE (featureIndex);
+	&& featureIndex.sanitize (context);
   }
 
   Offset	lookupOrder;	/* = Null (reserved for an offset to a
@@ -236,7 +236,7 @@ struct Feature
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE (lookupIndex);
+	&& lookupIndex.sanitize (context);
   }
 
   /* LONGTERMTODO: implement get_feature_parameters() */
@@ -292,7 +292,7 @@ struct Lookup
     if (unlikely (lookupFlag & LookupFlag::UseMarkFilteringSet))
     {
       USHORT &markFilteringSet = StructAfter<USHORT> (subTable);
-      if (!SANITIZE (markFilteringSet)) return false;
+      if (!markFilteringSet.sanitize (context)) return false;
     }
     return true;
   }
@@ -336,7 +336,7 @@ struct CoverageFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (glyphArray);
+    return glyphArray.sanitize (context);
   }
 
   private:
@@ -395,7 +395,7 @@ struct CoverageFormat2
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (rangeRecord);
+    return rangeRecord.sanitize (context);
   }
 
   private:
@@ -422,7 +422,7 @@ struct Coverage
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -458,7 +458,7 @@ struct ClassDefFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE (classValue);
+	&& classValue.sanitize (context);
   }
 
   USHORT	classFormat;		/* Format identifier--format = 1 */
@@ -516,7 +516,7 @@ struct ClassDefFormat2
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (rangeRecord);
+    return rangeRecord.sanitize (context);
   }
 
   USHORT	classFormat;	/* Format identifier--format = 2 */
@@ -541,7 +541,7 @@ struct ClassDef
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh
index 9be16a3..76b3ffc 100644
--- a/src/hb-ot-layout-gdef-private.hh
+++ b/src/hb-ot-layout-gdef-private.hh
@@ -176,7 +176,7 @@ struct CaretValue
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -291,7 +291,7 @@ struct MarkGlyphSets
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -351,7 +351,7 @@ struct GDEF
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (version) && likely (version.major == 1)
+    return version.sanitize (context) && likely (version.major == 1)
 	&& glyphClassDef.sanitize (context, this)
 	&& attachList.sanitize (context, this)
 	&& ligCaretList.sanitize (context, this)
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 3f67b14..95d9353 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -318,7 +318,7 @@ struct Anchor
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -526,7 +526,7 @@ struct SinglePos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -776,7 +776,7 @@ struct PairPos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -1027,7 +1027,7 @@ struct CursivePos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -1125,7 +1125,7 @@ struct MarkBasePos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -1250,7 +1250,7 @@ struct MarkLigPos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -1354,7 +1354,7 @@ struct MarkMarkPos
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -1455,7 +1455,7 @@ struct PosLookupSubTable
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case Single:		return u.single->sanitize (context);
     case Pair:			return u.pair->sanitize (context);
@@ -1604,7 +1604,7 @@ inline bool ExtensionPos::sanitize (hb_sanitize_context_t *context)
   if (unlikely (!Extension::sanitize (context))) return false;
   unsigned int offset = get_offset ();
   if (unlikely (!offset)) return true;
-  return SANITIZE (StructAtOffset<PosLookupSubTable> (*this, offset));
+  return StructAtOffset<PosLookupSubTable> (*this, offset).sanitize (context);
 }
 
 static inline bool position_lookup (hb_apply_context_t *context, unsigned int lookup_index)
diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh
index 461e9a9..5585409 100644
--- a/src/hb-ot-layout-gsub-private.hh
+++ b/src/hb-ot-layout-gsub-private.hh
@@ -61,7 +61,7 @@ struct SingleSubstFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return coverage.sanitize (context, this)
-	&& SANITIZE (deltaGlyphID);
+	&& deltaGlyphID.sanitize (context);
   }
 
   private:
@@ -104,7 +104,7 @@ struct SingleSubstFormat2
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return coverage.sanitize (context, this)
-	&& SANITIZE (substitute);
+	&& substitute.sanitize (context);
   }
 
   private:
@@ -136,7 +136,7 @@ struct SingleSubst
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -186,7 +186,7 @@ struct Sequence
   public:
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (substitute);
+    return substitute.sanitize (context);
   }
 
   private:
@@ -246,7 +246,7 @@ struct MultipleSubst
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -342,7 +342,7 @@ struct AlternateSubst
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -428,8 +428,8 @@ struct Ligature
   public:
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (ligGlyph)
-        && SANITIZE (component);
+    return ligGlyph.sanitize (context)
+        && component.sanitize (context);
   }
 
   private:
@@ -526,7 +526,7 @@ struct LigatureSubst
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -633,7 +633,7 @@ struct ReverseChainSingleSubstFormat1
     if (!lookahead.sanitize (context, this))
       return false;
     ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
-    return SANITIZE (substitute);
+    return substitute.sanitize (context);
   }
 
   private:
@@ -671,7 +671,7 @@ struct ReverseChainSingleSubst
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -724,7 +724,7 @@ struct SubstLookupSubTable
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case Single:		return u.single->sanitize (context);
     case Multiple:		return u.multiple->sanitize (context);
@@ -908,7 +908,7 @@ inline bool ExtensionSubst::sanitize (hb_sanitize_context_t *context)
   if (unlikely (!Extension::sanitize (context))) return false;
   unsigned int offset = get_offset ();
   if (unlikely (!offset)) return true;
-  return SANITIZE (StructAtOffset<SubstLookupSubTable> (*this, offset));
+  return StructAtOffset<SubstLookupSubTable> (*this, offset).sanitize (context);
 }
 
 inline bool ExtensionSubst::is_reverse (void) const
diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh
index 86d6405..9f2ab4a 100644
--- a/src/hb-ot-layout-gsubgpos-private.hh
+++ b/src/hb-ot-layout-gsubgpos-private.hh
@@ -287,8 +287,8 @@ struct Rule
   public:
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (inputCount)
-	&& SANITIZE (lookupCount)
+    return inputCount.sanitize (context)
+	&& lookupCount.sanitize (context)
 	&& context->check_range (input,
 				 input[0].get_size () * inputCount
 				 + lookupRecordX[0].get_size () * lookupCount);
@@ -481,7 +481,7 @@ struct Context
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -566,13 +566,13 @@ struct ChainRule
   public:
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (backtrack)) return false;
+    if (!backtrack.sanitize (context)) return false;
     HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
-    if (!SANITIZE (input)) return false;
+    if (!input.sanitize (context)) return false;
     ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
-    if (!SANITIZE (lookahead)) return false;
+    if (!lookahead.sanitize (context)) return false;
     ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
-    return SANITIZE (lookup);
+    return lookup.sanitize (context);
   }
 
   private:
@@ -756,7 +756,7 @@ struct ChainContextFormat3
     OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
     if (!lookahead.sanitize (context, this)) return false;
     ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
-    return SANITIZE (lookup);
+    return lookup.sanitize (context);
   }
 
   private:
@@ -795,7 +795,7 @@ struct ChainContext
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     case 2: return u.format2->sanitize (context);
@@ -856,7 +856,7 @@ struct Extension
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.format)) return false;
+    if (!u.format.sanitize (context)) return false;
     switch (u.format) {
     case 1: return u.format1->sanitize (context);
     default:return true;
@@ -913,7 +913,7 @@ struct GSUBGPOS
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE (version) && likely (version.major == 1)
+    return version.sanitize (context) && likely (version.major == 1)
 	&& scriptList.sanitize (context, this)
 	&& featureList.sanitize (context, this)
 	&& lookupList.sanitize (context, this);
commit c2ddfd2d268385257c77c09a9abeacf4230d5377
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 13:06:15 2010 -0400

    Cleanup Value casts

diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index a3db7b5..3f67b14 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -38,7 +38,7 @@
 
 /* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
 
-typedef SHORT Value;
+typedef USHORT Value;
 
 typedef Value ValueRecord[VAR0];
 ASSERT_SIZE_VAR (ValueRecord, 0, Value);
@@ -106,10 +106,10 @@ struct ValueFormat : USHORT
     x_scale = layout->font->x_scale;
     y_scale = layout->font->y_scale;
     /* design units -> fractional pixel */
-    if (format & xPlacement) glyph_pos->x_offset  += _hb_16dot16_mul_round (x_scale, *CastP<SHORT> (values++));
-    if (format & yPlacement) glyph_pos->y_offset  += _hb_16dot16_mul_round (y_scale, *CastP<SHORT> (values++));
-    if (format & xAdvance)   glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, *CastP<SHORT> (values++));
-    if (format & yAdvance)   glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, *CastP<SHORT> (values++));
+    if (format & xPlacement) glyph_pos->x_offset  += _hb_16dot16_mul_round (x_scale, get_short (values++));
+    if (format & yPlacement) glyph_pos->y_offset  += _hb_16dot16_mul_round (y_scale, get_short (values++));
+    if (format & xAdvance)   glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, get_short (values++));
+    if (format & yAdvance)   glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, get_short (values++));
 
     if (!has_device ()) return;
 
@@ -120,16 +120,16 @@ struct ValueFormat : USHORT
 
     /* pixel -> fractional pixel */
     if (format & xPlaDevice) {
-      if (x_ppem) glyph_pos->x_offset  += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (x_ppem) << 16; else values++;
+      if (x_ppem) glyph_pos->x_offset  += (base + get_device (values++)).get_delta (x_ppem) << 16; else values++;
     }
     if (format & yPlaDevice) {
-      if (y_ppem) glyph_pos->y_offset  += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (y_ppem) << 16; else values++;
+      if (y_ppem) glyph_pos->y_offset  += (base + get_device (values++)).get_delta (y_ppem) << 16; else values++;
     }
     if (format & xAdvDevice) {
-      if (x_ppem) glyph_pos->x_advance += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (x_ppem) << 16; else values++;
+      if (x_ppem) glyph_pos->x_advance += (base + get_device (values++)).get_delta (x_ppem) << 16; else values++;
     }
     if (format & yAdvDevice) {
-      if (y_ppem) glyph_pos->y_advance += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (y_ppem) << 16; else values++;
+      if (y_ppem) glyph_pos->y_advance += (base + get_device (values++)).get_delta (y_ppem) << 16; else values++;
     }
   }
 
@@ -142,14 +142,22 @@ struct ValueFormat : USHORT
     if (format & xAdvance)   values++;
     if (format & yAdvance)   values++;
 
-    if ((format & xPlaDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
-    if ((format & yPlaDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
-    if ((format & xAdvDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
-    if ((format & yAdvDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
+    if ((format & xPlaDevice) && !get_device (values++).sanitize (context, base)) return false;
+    if ((format & yPlaDevice) && !get_device (values++).sanitize (context, base)) return false;
+    if ((format & xAdvDevice) && !get_device (values++).sanitize (context, base)) return false;
+    if ((format & yAdvDevice) && !get_device (values++).sanitize (context, base)) return false;
 
     return true;
   }
 
+  static inline OffsetTo<Device>& get_device (Value* value)
+  { return *CastP<OffsetTo<Device> > (value); }
+  static inline const OffsetTo<Device>& get_device (const Value* value)
+  { return *CastP<OffsetTo<Device> > (value); }
+
+  static inline const SHORT& get_short (const Value* value)
+  { return *CastP<SHORT> (value); }
+
   public:
 
   inline bool has_device () const {
commit 41a93d2c1ff175ef06328a99983577459c2d34b0
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 12:55:14 2010 -0400

    Remove SANITIZE_WITH_BASE

diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh
index 1c1a8d6..4e4494d 100644
--- a/src/hb-open-file-private.hh
+++ b/src/hb-open-file-private.hh
@@ -127,7 +127,7 @@ struct TTCHeaderVersion1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, table);
+    return table.sanitize (context, this);
   }
 
   private:
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 68b5037..499754f 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -240,8 +240,6 @@ struct hb_sanitize_context_t
 
 #define SANITIZE(X) likely ((X).sanitize (context))
 
-#define SANITIZE_WITH_BASE(B,X) likely ((X).sanitize (context, CharP(B)))
-
 #define SANITIZE_SELF() likely(context->check_range (this, sizeof (*this)))
 
 
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 9b245a1..1a4be0f 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -56,7 +56,7 @@ struct Record
   inline bool sanitize (hb_sanitize_context_t *context, void *base) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (base, offset);
+	&& offset.sanitize (context, base);
   }
 
   Tag		tag;		/* 4-byte Tag identifier */
@@ -204,8 +204,8 @@ struct Script
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, defaultLangSys)
-	&& SANITIZE_WITH_BASE (this, langSys);
+    return defaultLangSys.sanitize (context, this)
+	&& langSys.sanitize (context, this);
   }
 
   private:
diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh
index 65b2414..9be16a3 100644
--- a/src/hb-ot-layout-gdef-private.hh
+++ b/src/hb-ot-layout-gdef-private.hh
@@ -69,8 +69,8 @@ struct AttachList
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, attachPoint);
+    return coverage.sanitize (context, this)
+	&& attachPoint.sanitize (context, this);
   }
 
   private:
@@ -149,7 +149,7 @@ struct CaretValueFormat3
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (this, deviceTable);
+	&& deviceTable.sanitize (context, this);
   }
 
   private:
@@ -214,7 +214,7 @@ struct LigGlyph
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, carets);
+    return carets.sanitize (context, this);
   }
 
   private:
@@ -246,8 +246,8 @@ struct LigCaretList
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, ligGlyph);
+    return coverage.sanitize (context, this)
+	&& ligGlyph.sanitize (context, this);
   }
 
   private:
@@ -268,7 +268,7 @@ struct MarkGlyphSetsFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage);
+    return coverage.sanitize (context, this);
   }
 
   private:
@@ -352,11 +352,11 @@ struct GDEF
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE (version) && likely (version.major == 1)
-	&& SANITIZE_WITH_BASE (this, glyphClassDef)
-	&& SANITIZE_WITH_BASE (this, attachList)
-	&& SANITIZE_WITH_BASE (this, ligCaretList)
-	&& SANITIZE_WITH_BASE (this, markAttachClassDef)
-	&& (version < 0x00010002 || SANITIZE_WITH_BASE (this, markGlyphSetsDef[0]));
+	&& glyphClassDef.sanitize (context, this)
+	&& attachList.sanitize (context, this)
+	&& ligCaretList.sanitize (context, this)
+	&& markAttachClassDef.sanitize (context, this)
+	&& (version < 0x00010002 || markGlyphSetsDef[0].sanitize (context, this));
   }
 
   private:
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index d41d8a1..a3db7b5 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright (C) 2007,2008,2009,2010  Red Hat, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -106,10 +106,10 @@ struct ValueFormat : USHORT
     x_scale = layout->font->x_scale;
     y_scale = layout->font->y_scale;
     /* design units -> fractional pixel */
-    if (format & xPlacement) glyph_pos->x_offset  += _hb_16dot16_mul_round (x_scale, *(SHORT*)values++);
-    if (format & yPlacement) glyph_pos->y_offset  += _hb_16dot16_mul_round (y_scale, *(SHORT*)values++);
-    if (format & xAdvance)   glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, *(SHORT*)values++);
-    if (format & yAdvance)   glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, *(SHORT*)values++);
+    if (format & xPlacement) glyph_pos->x_offset  += _hb_16dot16_mul_round (x_scale, *CastP<SHORT> (values++));
+    if (format & yPlacement) glyph_pos->y_offset  += _hb_16dot16_mul_round (y_scale, *CastP<SHORT> (values++));
+    if (format & xAdvance)   glyph_pos->x_advance += _hb_16dot16_mul_round (x_scale, *CastP<SHORT> (values++));
+    if (format & yAdvance)   glyph_pos->y_advance += _hb_16dot16_mul_round (y_scale, *CastP<SHORT> (values++));
 
     if (!has_device ()) return;
 
@@ -120,21 +120,21 @@ struct ValueFormat : USHORT
 
     /* pixel -> fractional pixel */
     if (format & xPlaDevice) {
-      if (x_ppem) glyph_pos->x_offset  += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 16; else values++;
+      if (x_ppem) glyph_pos->x_offset  += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (x_ppem) << 16; else values++;
     }
     if (format & yPlaDevice) {
-      if (y_ppem) glyph_pos->y_offset  += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 16; else values++;
+      if (y_ppem) glyph_pos->y_offset  += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (y_ppem) << 16; else values++;
     }
     if (format & xAdvDevice) {
-      if (x_ppem) glyph_pos->x_advance += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 16; else values++;
+      if (x_ppem) glyph_pos->x_advance += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (x_ppem) << 16; else values++;
     }
     if (format & yAdvDevice) {
-      if (y_ppem) glyph_pos->y_advance += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 16; else values++;
+      if (y_ppem) glyph_pos->y_advance += (base+*CastP<OffsetTo<Device> >(values++)).get_delta (y_ppem) << 16; else values++;
     }
   }
 
   private:
-  inline bool sanitize_value_devices (hb_sanitize_context_t *context, void *base, const Value *values) {
+  inline bool sanitize_value_devices (hb_sanitize_context_t *context, void *base, Value *values) {
     unsigned int format = *this;
 
     if (format & xPlacement) values++;
@@ -142,10 +142,10 @@ struct ValueFormat : USHORT
     if (format & xAdvance)   values++;
     if (format & yAdvance)   values++;
 
-    if ((format & xPlaDevice) && !SANITIZE_WITH_BASE (base, *(OffsetTo<Device>*)values++)) return false;
-    if ((format & yPlaDevice) && !SANITIZE_WITH_BASE (base, *(OffsetTo<Device>*)values++)) return false;
-    if ((format & xAdvDevice) && !SANITIZE_WITH_BASE (base, *(OffsetTo<Device>*)values++)) return false;
-    if ((format & yAdvDevice) && !SANITIZE_WITH_BASE (base, *(OffsetTo<Device>*)values++)) return false;
+    if ((format & xPlaDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
+    if ((format & yPlaDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
+    if ((format & xAdvDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
+    if ((format & yAdvDevice) && !CastP<OffsetTo<Device> > (values++)->sanitize (context, base)) return false;
 
     return true;
   }
@@ -157,13 +157,13 @@ struct ValueFormat : USHORT
     return (format & devices) != 0;
   }
 
-  inline bool sanitize_value (hb_sanitize_context_t *context, void *base, const Value *values) {
+  inline bool sanitize_value (hb_sanitize_context_t *context, void *base, Value *values) {
     TRACE_SANITIZE ();
     return context->check_range (values, get_size ())
 	&& (!has_device () || sanitize_value_devices (context, base, values));
   }
 
-  inline bool sanitize_values (hb_sanitize_context_t *context, void *base, const Value *values, unsigned int count) {
+  inline bool sanitize_values (hb_sanitize_context_t *context, void *base, Value *values, unsigned int count) {
     TRACE_SANITIZE ();
     unsigned int len = get_len ();
 
@@ -181,7 +181,7 @@ struct ValueFormat : USHORT
   }
 
   /* Just sanitize referenced Device tables.  Doesn't check the values themselves. */
-  inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *context, void *base, const Value *values, unsigned int count, unsigned int stride) {
+  inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *context, void *base, Value *values, unsigned int count, unsigned int stride) {
     TRACE_SANITIZE ();
 
     if (!has_device ()) return true;
@@ -275,8 +275,8 @@ struct AnchorFormat3
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (this, xDeviceTable)
-	&& SANITIZE_WITH_BASE (this, yDeviceTable);
+	&& xDeviceTable.sanitize (context, this)
+	&& yDeviceTable.sanitize (context, this);
   }
 
   private:
@@ -343,7 +343,7 @@ struct AnchorMatrix
     unsigned int count = rows * cols;
     if (!context->check_array (matrix, matrix[0].get_size (), count)) return false;
     for (unsigned int i = 0; i < count; i++)
-      if (!SANITIZE_WITH_BASE (this, matrix[i])) return false;
+      if (!matrix[i].sanitize (context, this)) return false;
     return true;
   }
 
@@ -365,7 +365,7 @@ struct MarkRecord
   inline bool sanitize (hb_sanitize_context_t *context, void *base) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (base, markAnchor);
+	&& markAnchor.sanitize (context, base);
   }
 
   private:
@@ -408,7 +408,7 @@ struct MarkArray
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, markRecord);
+    return markRecord.sanitize (context, this);
   }
 
   private:
@@ -441,7 +441,7 @@ struct SinglePosFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (this, coverage)
+	&& coverage.sanitize (context, this)
 	&& valueFormat.sanitize_value (context, CharP(this), values);
   }
 
@@ -484,7 +484,7 @@ struct SinglePosFormat2
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (this, coverage)
+	&& coverage.sanitize (context, this)
 	&& valueFormat.sanitize_values (context, CharP(this), values, valueCount);
   }
 
@@ -623,7 +623,7 @@ struct PairPosFormat1
     unsigned int len2 = valueFormat2.get_len ();
 
     if (!(SANITIZE_SELF ()
-       && SANITIZE_WITH_BASE (this, coverage)
+       && coverage.sanitize (context, this)
        && likely (pairSet.sanitize (context, CharP(this), len1 + len2)))) return false;
 
     if (!(valueFormat1.has_device () || valueFormat2.has_device ())) return true;
@@ -632,10 +632,10 @@ struct PairPosFormat1
     unsigned int count1 = pairSet.len;
     for (unsigned int i = 0; i < count1; i++)
     {
-      const PairSet &pair_set = this+pairSet[i];
+      PairSet &pair_set = const_cast<PairSet &> (this+pairSet[i]); /* XXX clean this up */
 
       unsigned int count2 = pair_set.len;
-      const PairValueRecord *record = pair_set.array;
+      PairValueRecord *record = pair_set.array;
       if (!(valueFormat1.sanitize_values_stride_unsafe (context, CharP(this), &record->values[0], count2, stride) &&
 	    valueFormat2.sanitize_values_stride_unsafe (context, CharP(this), &record->values[len1], count2, stride)))
         return false;
@@ -708,9 +708,9 @@ struct PairPosFormat2
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     if (!(SANITIZE_SELF ()
-       && SANITIZE_WITH_BASE (this, coverage)
-       && SANITIZE_WITH_BASE (this, classDef1)
-       && SANITIZE_WITH_BASE (this, classDef2))) return false;
+       && coverage.sanitize (context, this)
+       && classDef1.sanitize (context, this)
+       && classDef2.sanitize (context, this))) return false;
 
     unsigned int len1 = valueFormat1.get_len ();
     unsigned int len2 = valueFormat2.get_len ();
@@ -791,8 +791,8 @@ struct EntryExitRecord
 
   inline bool sanitize (hb_sanitize_context_t *context, void *base) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (base, entryAnchor)
-	&& SANITIZE_WITH_BASE (base, exitAnchor);
+    return entryAnchor.sanitize (context, base)
+	&& exitAnchor.sanitize (context, base);
   }
 
   OffsetTo<Anchor>
@@ -988,8 +988,8 @@ struct CursivePosFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, entryExitRecord);
+    return coverage.sanitize (context, this)
+	&& entryExitRecord.sanitize (context, this);
   }
 
   private:
@@ -1077,9 +1077,9 @@ struct MarkBasePosFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-        && SANITIZE_WITH_BASE (this, markCoverage)
-	&& SANITIZE_WITH_BASE (this, baseCoverage)
-	&& SANITIZE_WITH_BASE (this, markArray)
+        && markCoverage.sanitize (context, this)
+	&& baseCoverage.sanitize (context, this)
+	&& markArray.sanitize (context, this)
 	&& likely (baseArray.sanitize (context, CharP(this), (unsigned int) classCount));
   }
 
@@ -1201,9 +1201,9 @@ struct MarkLigPosFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-        && SANITIZE_WITH_BASE (this, markCoverage)
-	&& SANITIZE_WITH_BASE (this, ligatureCoverage)
-	&& SANITIZE_WITH_BASE (this, markArray)
+        && markCoverage.sanitize (context, this)
+	&& ligatureCoverage.sanitize (context, this)
+	&& markArray.sanitize (context, this)
 	&& likely (ligatureArray.sanitize (context, CharP(this), (unsigned int) classCount));
   }
 
@@ -1304,9 +1304,9 @@ struct MarkMarkPosFormat1
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_WITH_BASE (this, mark1Coverage)
-	&& SANITIZE_WITH_BASE (this, mark2Coverage)
-	&& SANITIZE_WITH_BASE (this, mark1Array)
+	&& mark1Coverage.sanitize (context, this)
+	&& mark2Coverage.sanitize (context, this)
+	&& mark1Array.sanitize (context, this)
 	&& likely (mark2Array.sanitize (context, CharP(this), (unsigned int) classCount));
   }
 
@@ -1548,7 +1548,7 @@ struct PosLookup : Lookup
     TRACE_SANITIZE ();
     if (unlikely (!Lookup::sanitize (context))) return false;
     OffsetArrayOf<PosLookupSubTable> &list = CastR<OffsetArrayOf<PosLookupSubTable> > (subTable);
-    return SANITIZE_WITH_BASE (this, list);
+    return list.sanitize (context, this);
   }
 };
 
@@ -1576,7 +1576,7 @@ struct GPOS : GSUBGPOS
     TRACE_SANITIZE ();
     if (unlikely (!GSUBGPOS::sanitize (context))) return false;
     OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList);
-    return SANITIZE_WITH_BASE (this, list);
+    return list.sanitize (context, this);
   }
 };
 ASSERT_SIZE (GPOS, 10);
diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh
index 9083db5..461e9a9 100644
--- a/src/hb-ot-layout-gsub-private.hh
+++ b/src/hb-ot-layout-gsub-private.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright (C) 2007,2008,2009,2010  Red Hat, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -60,7 +60,7 @@ struct SingleSubstFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
+    return coverage.sanitize (context, this)
 	&& SANITIZE (deltaGlyphID);
   }
 
@@ -103,7 +103,7 @@ struct SingleSubstFormat2
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
+    return coverage.sanitize (context, this)
 	&& SANITIZE (substitute);
   }
 
@@ -214,8 +214,8 @@ struct MultipleSubstFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, sequence);
+    return coverage.sanitize (context, this)
+	&& sequence.sanitize (context, this);
   }
 
   private:
@@ -310,8 +310,8 @@ struct AlternateSubstFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, alternateSet);
+    return coverage.sanitize (context, this)
+	&& alternateSet.sanitize (context, this);
   }
 
   private:
@@ -463,7 +463,7 @@ struct LigatureSet
   public:
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, ligature);
+    return ligature.sanitize (context, this);
   }
 
   private:
@@ -495,8 +495,8 @@ struct LigatureSubstFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, ligatureSet);
+    return coverage.sanitize (context, this)
+	&& ligatureSet.sanitize (context, this);
   }
 
   private:
@@ -626,11 +626,11 @@ struct ReverseChainSingleSubstFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!(SANITIZE_WITH_BASE (this, coverage)
-       && SANITIZE_WITH_BASE (this, backtrack)))
+    if (!(coverage.sanitize (context, this)
+       && backtrack.sanitize (context, this)))
       return false;
     OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
-    if (!SANITIZE_WITH_BASE (this, lookahead))
+    if (!lookahead.sanitize (context, this))
       return false;
     ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
     return SANITIZE (substitute);
@@ -860,7 +860,7 @@ struct SubstLookup : Lookup
     TRACE_SANITIZE ();
     if (unlikely (!Lookup::sanitize (context))) return false;
     OffsetArrayOf<SubstLookupSubTable> &list = CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable);
-    return SANITIZE_WITH_BASE (this, list);
+    return list.sanitize (context, this);
   }
 };
 
@@ -884,12 +884,11 @@ struct GSUB : GSUBGPOS
 				 hb_mask_t     mask) const
   { return get_lookup (lookup_index).apply_string (layout, buffer, mask); }
 
-
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     if (unlikely (!GSUBGPOS::sanitize (context))) return false;
     OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList);
-    return SANITIZE_WITH_BASE (this, list);
+    return list.sanitize (context, this);
   }
 };
 ASSERT_SIZE (GSUB, 10);
diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh
index 86c2153..86d6405 100644
--- a/src/hb-ot-layout-gsubgpos-private.hh
+++ b/src/hb-ot-layout-gsubgpos-private.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright (C) 2007,2008,2009,2010  Red Hat, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -323,7 +323,7 @@ struct RuleSet
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, rule);
+    return rule.sanitize (context, this);
   }
 
   private:
@@ -355,8 +355,8 @@ struct ContextFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, ruleSet);
+    return coverage.sanitize (context, this)
+	&& ruleSet.sanitize (context, this);
   }
 
   private:
@@ -398,9 +398,9 @@ struct ContextFormat2
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-        && SANITIZE_WITH_BASE (this, classDef)
-	&& SANITIZE_WITH_BASE (this, ruleSet);
+    return coverage.sanitize (context, this)
+        && classDef.sanitize (context, this)
+	&& ruleSet.sanitize (context, this);
   }
 
   private:
@@ -447,7 +447,7 @@ struct ContextFormat3
     unsigned int count = glyphCount;
     if (!context->check_array (coverage, OffsetTo<Coverage>::get_size (), count)) return false;
     for (unsigned int i = 0; i < count; i++)
-      if (!SANITIZE_WITH_BASE (this, coverage[i])) return false;
+      if (!coverage[i].sanitize (context, this)) return false;
     LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, OffsetTo<Coverage>::get_size () * count);
     return context->check_array (lookupRecord, LookupRecord::get_size (), lookupCount);
   }
@@ -609,7 +609,7 @@ struct ChainRuleSet
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, rule);
+    return rule.sanitize (context, this);
   }
 
   private:
@@ -641,8 +641,8 @@ struct ChainContextFormat1
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, ruleSet);
+    return coverage.sanitize (context, this)
+	&& ruleSet.sanitize (context, this);
   }
 
   private:
@@ -688,11 +688,11 @@ struct ChainContextFormat2
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    return SANITIZE_WITH_BASE (this, coverage)
-	&& SANITIZE_WITH_BASE (this, backtrackClassDef)
-	&& SANITIZE_WITH_BASE (this, inputClassDef)
-	&& SANITIZE_WITH_BASE (this, lookaheadClassDef)
-	&& SANITIZE_WITH_BASE (this, ruleSet);
+    return coverage.sanitize (context, this)
+	&& backtrackClassDef.sanitize (context, this)
+	&& inputClassDef.sanitize (context, this)
+	&& lookaheadClassDef.sanitize (context, this)
+	&& ruleSet.sanitize (context, this);
   }
 
   private:
@@ -750,11 +750,11 @@ struct ChainContextFormat3
 
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
-    if (!SANITIZE_WITH_BASE (this, backtrack)) return false;
+    if (!backtrack.sanitize (context, this)) return false;
     OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
-    if (!SANITIZE_WITH_BASE (this, input)) return false;
+    if (!input.sanitize (context, this)) return false;
     OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
-    if (!SANITIZE_WITH_BASE (this, lookahead)) return false;
+    if (!lookahead.sanitize (context, this)) return false;
     ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
     return SANITIZE (lookup);
   }
@@ -914,9 +914,9 @@ struct GSUBGPOS
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE (version) && likely (version.major == 1)
-	&& SANITIZE_WITH_BASE (this, scriptList)
-	&& SANITIZE_WITH_BASE (this, featureList)
-	&& SANITIZE_WITH_BASE (this, lookupList);
+	&& scriptList.sanitize (context, this)
+	&& featureList.sanitize (context, this)
+	&& lookupList.sanitize (context, this);
   }
 
   protected:
commit f5fab0c71837371cce32dc3e9edca1ccb8d44e29
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 10:26:52 2010 -0400

    Remove SANITIZE_MEM

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 741ee7c..68b5037 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -242,9 +242,7 @@ struct hb_sanitize_context_t
 
 #define SANITIZE_WITH_BASE(B,X) likely ((X).sanitize (context, CharP(B)))
 
-#define SANITIZE_SELF() SANITIZE_MEM(this, sizeof (*this))
-
-#define SANITIZE_MEM(B,L) likely (context->check_range (CharP(B), (L)))
+#define SANITIZE_SELF() likely(context->check_range (this, sizeof (*this)))
 
 
 /* Template to sanitize an object. */
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 22a5432..9b245a1 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -599,7 +599,7 @@ struct Device
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF()
-	&& SANITIZE_MEM (this, this->get_size ());
+	&& context->check_range (this, this->get_size ());
   }
 
   private:
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 98cc371..d41d8a1 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -159,7 +159,7 @@ struct ValueFormat : USHORT
 
   inline bool sanitize_value (hb_sanitize_context_t *context, void *base, const Value *values) {
     TRACE_SANITIZE ();
-    return SANITIZE_MEM (values, get_size ())
+    return context->check_range (values, get_size ())
 	&& (!has_device () || sanitize_value_devices (context, base, values));
   }
 
diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh
index bb10bdf..86c2153 100644
--- a/src/hb-ot-layout-gsubgpos-private.hh
+++ b/src/hb-ot-layout-gsubgpos-private.hh
@@ -289,9 +289,9 @@ struct Rule
     TRACE_SANITIZE ();
     return SANITIZE (inputCount)
 	&& SANITIZE (lookupCount)
-	&& SANITIZE_MEM (input,
-			 input[0].get_size () * inputCount +
-			 lookupRecordX[0].get_size () * lookupCount);
+	&& context->check_range (input,
+				 input[0].get_size () * inputCount
+				 + lookupRecordX[0].get_size () * lookupCount);
   }
 
   private:
commit 4ad2cc5dec6b0639da2b1846282bdd99d06d5ff1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 6 09:24:24 2010 -0400

    Rename check to check_range

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index ea95c07..741ee7c 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -181,14 +181,14 @@ struct hb_sanitize_context_t
     this->start = this->end = NULL;
   }
 
-  inline bool check (const void *base, unsigned int len) const
+  inline bool check_range (const void *base, unsigned int len) const
   {
     bool ret = this->start <= base &&
 	       base <= this->end &&
 	       (unsigned int) (this->end - CharP(base)) >= len;
 
     if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE) \
-      fprintf (stderr, "SANITIZE(%p) %-*d-> check [%p..%p] (%d bytes) in [%p..%p] -> %s\n", \
+      fprintf (stderr, "SANITIZE(%p) %-*d-> range [%p..%p] (%d bytes) in [%p..%p] -> %s\n", \
 	       base,
 	       this->debug_depth, this->debug_depth,
 	       base, CharP(base)+len, len,
@@ -211,7 +211,7 @@ struct hb_sanitize_context_t
 	       this->start, this->end,
 	       !overflows ? "does not overflow" : "OVERFLOWS FAIL");
 
-    return likely (!overflows && this->check (base, record_size * len));
+    return likely (!overflows && this->check_range (base, record_size * len));
   }
 
   inline bool can_edit (const char *base HB_UNUSED, unsigned int len HB_UNUSED)
@@ -244,7 +244,7 @@ struct hb_sanitize_context_t
 
 #define SANITIZE_SELF() SANITIZE_MEM(this, sizeof (*this))
 
-#define SANITIZE_MEM(B,L) likely (context->check (CharP(B), (L)))
+#define SANITIZE_MEM(B,L) likely (context->check_range (CharP(B), (L)))
 
 
 /* Template to sanitize an object. */
commit 1cd1e117d060d38e314618b627d7663cb01ed584
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 5 20:15:14 2010 -0400

    Remove SANITIZE_ARRAY

diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh
index 5684383..1c1a8d6 100644
--- a/src/hb-open-file-private.hh
+++ b/src/hb-open-file-private.hh
@@ -101,7 +101,7 @@ typedef struct OffsetTable
   inline bool sanitize (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF ()
-	&& SANITIZE_ARRAY (tableDir, TableDirectory::get_size (), numTables);
+	&& context->check_array (tableDir, TableDirectory::get_size (), numTables);
   }
 
   private:
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 8e90133..ea95c07 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -181,24 +181,24 @@ struct hb_sanitize_context_t
     this->start = this->end = NULL;
   }
 
-  inline bool check (const char *base, unsigned int len) const
+  inline bool check (const void *base, unsigned int len) const
   {
     bool ret = this->start <= base &&
 	       base <= this->end &&
-	       (unsigned int) (this->end - base) >= len;
+	       (unsigned int) (this->end - CharP(base)) >= len;
 
     if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE) \
       fprintf (stderr, "SANITIZE(%p) %-*d-> check [%p..%p] (%d bytes) in [%p..%p] -> %s\n", \
 	       base,
 	       this->debug_depth, this->debug_depth,
-	       base, base+len, len,
+	       base, CharP(base)+len, len,
 	       this->start, this->end,
 	       ret ? "pass" : "FAIL");
 
     return likely (ret);
   }
 
-  inline bool check_array (const char *base, unsigned int record_size, unsigned int len) const
+  inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
   {
     bool overflows = len >= ((unsigned int) -1) / record_size;
 
@@ -207,7 +207,7 @@ struct hb_sanitize_context_t
       fprintf (stderr, "SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s\n", \
 	       base,
 	       this->debug_depth, this->debug_depth,
-	       base, base + (record_size * len), record_size, len, (unsigned long) record_size * len,
+	       base, CharP(base) + (record_size * len), record_size, len, (unsigned long) record_size * len,
 	       this->start, this->end,
 	       !overflows ? "does not overflow" : "OVERFLOWS FAIL");
 
@@ -246,8 +246,6 @@ struct hb_sanitize_context_t
 
 #define SANITIZE_MEM(B,L) likely (context->check (CharP(B), (L)))
 
-#define SANITIZE_ARRAY(A,S,L) likely (context->check_array (CharP(A), S, L))
-
 
 /* Template to sanitize an object. */
 template <typename Type>
@@ -556,7 +554,7 @@ struct GenericArrayOf
   inline bool sanitize_shallow (hb_sanitize_context_t *context) {
     TRACE_SANITIZE ();
     return SANITIZE_SELF()
-	&& SANITIZE_ARRAY (this, Type::get_size (), len);
+	&& context->check_array (this, Type::get_size (), len);
   }
 
   public:
@@ -624,7 +622,7 @@ struct HeadlessArrayOf
 
   inline bool sanitize_shallow (hb_sanitize_context_t *context) {
     return SANITIZE_SELF()
-	&& SANITIZE_ARRAY (this, Type::get_size (), len);
+	&& context->check_array (this, Type::get_size (), len);
   }
 
   inline bool sanitize (hb_sanitize_context_t *context) {
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 145fc04..98cc371 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -167,7 +167,7 @@ struct ValueFormat : USHORT
     TRACE_SANITIZE ();
     unsigned int len = get_len ();
 
-    if (!SANITIZE_ARRAY (values, get_size (), count)) return false;
+    if (!context->check_array (values, get_size (), count)) return false;
 
     if (!has_device ()) return true;
 
@@ -341,7 +341,7 @@ struct AnchorMatrix
     if (!SANITIZE_SELF ()) return false;
     if (unlikely (cols >= ((unsigned int) -1) / rows)) return false;
     unsigned int count = rows * cols;
-    if (!SANITIZE_ARRAY (matrix, matrix[0].get_size (), count)) return false;
+    if (!context->check_array (matrix, matrix[0].get_size (), count)) return false;
     for (unsigned int i = 0; i < count; i++)
       if (!SANITIZE_WITH_BASE (this, matrix[i])) return false;
     return true;
@@ -557,7 +557,7 @@ struct PairSet
     TRACE_SANITIZE ();
     if (!SANITIZE_SELF ()) return false;
     unsigned int count = (1 + format_len) * len;
-    return SANITIZE_ARRAY (array, USHORT::get_size (), count);
+    return context->check_array (array, USHORT::get_size (), count);
   }
 
   private:
@@ -717,7 +717,7 @@ struct PairPosFormat2
     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 SANITIZE_ARRAY (values, record_size, count) &&
+    return context->check_array (values, record_size, count) &&
 	   valueFormat1.sanitize_values_stride_unsafe (context, CharP(this), &values[0], count, stride) &&
 	   valueFormat2.sanitize_values_stride_unsafe (context, CharP(this), &values[len1], count, stride);
   }
diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh
index 6ed1bf7..bb10bdf 100644
--- a/src/hb-ot-layout-gsubgpos-private.hh
+++ b/src/hb-ot-layout-gsubgpos-private.hh
@@ -445,11 +445,11 @@ struct ContextFormat3
     TRACE_SANITIZE ();
     if (!SANITIZE_SELF ()) return false;
     unsigned int count = glyphCount;
-    if (!SANITIZE_ARRAY (coverage, OffsetTo<Coverage>::get_size (), count)) return false;
+    if (!context->check_array (coverage, OffsetTo<Coverage>::get_size (), count)) return false;
     for (unsigned int i = 0; i < count; i++)
       if (!SANITIZE_WITH_BASE (this, coverage[i])) return false;
     LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, OffsetTo<Coverage>::get_size () * count);
-    return SANITIZE_ARRAY (lookupRecord, LookupRecord::get_size (), lookupCount);
+    return context->check_array (lookupRecord, LookupRecord::get_size (), lookupCount);
   }
 
   private:



More information about the HarfBuzz mailing list