From 196598bbccff08415ff5192314cba044df258cad Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 Aug 2009 11:04:32 -0400 Subject: [PATCH] [Hb] Use reinterpret casts instead of direct casts to char * --- src/hb-open-file-private.hh | 4 +-- src/hb-open-types-private.hh | 19 ++++++++---- src/hb-ot-layout-common-private.hh | 8 ++--- src/hb-ot-layout-gpos-private.hh | 12 ++++---- src/hb-ot-layout-gsub-private.hh | 20 ++++++------- src/hb-ot-layout-gsubgpos-private.hh | 44 ++++++++++++++-------------- 6 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 50b9bc202..50324895f 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -115,7 +115,7 @@ struct OpenTypeFontFile switch (tag) { default: return 0; case TrueTypeTag: case CFFTag: return 1; - case TTCTag: return TTCHeader::get_for_data ((const char *) this).table.len; + case TTCTag: return TTCHeader::get_for_data (CONST_CHARP(this)).table.len; } } const OpenTypeFontFace& get_face (unsigned int i) const @@ -126,7 +126,7 @@ struct OpenTypeFontFile * Apple dfont container is a container of SFNT's. So each SFNT is a * non-TTC, but the index is more than zero. */ case TrueTypeTag: case CFFTag: return *(const OffsetTable*)this; - case TTCTag: return this+TTCHeader::get_for_data ((const char *) this).table[i]; + case TTCTag: return this+TTCHeader::get_for_data (CONST_CHARP(this)).table[i]; } } diff --git a/src/hb-open-types-private.hh b/src/hb-open-types-private.hh index 82b4a061a..2ece79d22 100644 --- a/src/hb-open-types-private.hh +++ b/src/hb-open-types-private.hh @@ -38,6 +38,13 @@ #define MAX_NESTING_LEVEL 8 +/* + * Casts + */ + +#define CONST_CHARP(X) (reinterpret_cast(X)) +#define CHARP(X) ((char *)reinterpret_cast(X)) + /* * Sanitize @@ -58,7 +65,7 @@ struct _hb_sanitize_context_t #define SANITIZE(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG)) #define SANITIZE2(X,Y) SANITIZE (X) && SANITIZE (Y) -#define SANITIZE_THIS(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG, (const char *) this)) +#define SANITIZE_THIS(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG, reinterpret_cast(this))) #define SANITIZE_THIS2(X,Y) SANITIZE_THIS (X) && SANITIZE_THIS (Y) #define SANITIZE_THIS3(X,Y,Z) SANITIZE_THIS (X) && SANITIZE_THIS (Y) && SANITIZE_THIS(Z) @@ -66,7 +73,7 @@ struct _hb_sanitize_context_t #define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) #define SANITIZE_GET_SIZE() SANITIZE_MEM (this, this->get_size ()) -#define SANITIZE_MEM(B,L) HB_LIKELY (context->start <= (const char *)(B) && (const char *)(B) + (L) <= context->end) /* XXX overflow */ +#define SANITIZE_MEM(B,L) HB_LIKELY (context->start <= reinterpret_cast(B) && reinterpret_cast(B) + (L) <= context->end) /* XXX overflow */ #define NEUTER(Var, Val) (false) @@ -265,8 +272,8 @@ struct Tag : ULONG inline Tag (const char *c) { *(ULONG*)this = *(ULONG*)c; } inline bool operator== (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ - inline operator const char* (void) const { return (const char *)this; } - inline operator char* (void) { return (char *)this; } + inline operator const char* (void) const { return reinterpret_cast(this); } + inline operator char* (void) { return reinterpret_cast(this); } }; ASSERT_SIZE (Tag, 4); #define _NULL_TAG_INIT {' ', ' ', ' ', ' '} @@ -330,14 +337,14 @@ struct GenericOffsetTo : OffsetType { unsigned int offset = *this; if (HB_UNLIKELY (!offset)) return Null(Type); - return *(const Type*)((const char *) base + offset); + return *reinterpret_cast(reinterpret_cast(base) + offset); } inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { if (!SANITIZE_OBJ (*this)) return false; unsigned int offset = *this; if (HB_UNLIKELY (!offset)) return true; - return SANITIZE (*(Type*)((char *) base + offset)) || NEUTER (*this, 0); + return SANITIZE (*reinterpret_cast((char *)(reinterpret_cast(base) + offset))) || NEUTER (*this, 0); } }; template diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index dbea709d7..774b10a9e 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -78,7 +78,7 @@ struct RecordListOf : RecordArrayOf } inline bool sanitize (SANITIZE_ARG_DEF) { - return RecordArrayOf::sanitize (SANITIZE_ARG, (const char *) this); + return RecordArrayOf::sanitize (SANITIZE_ARG, CONST_CHARP(this)); } }; @@ -211,7 +211,7 @@ struct Lookup if (HB_UNLIKELY (flag & LookupFlag::UseMarkFilteringSet)) { const USHORT &markFilteringSet = *(const USHORT*) - ((const char *) &subTable + subTable.get_size ()); + (CONST_CHARP(&subTable) + subTable.get_size ()); flag += (markFilteringSet << 16); } return flag; @@ -221,7 +221,7 @@ struct Lookup if (!(SANITIZE_SELF () && SANITIZE_THIS (subTable))) return false; if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet)) { - USHORT &markFilteringSet = *(USHORT*) ((char *) &subTable + subTable.get_size ()); + USHORT &markFilteringSet = *(USHORT*) (CHARP(&subTable) + subTable.get_size ()); if (!SANITIZE (markFilteringSet)) return false; } return true; @@ -247,7 +247,7 @@ struct OffsetListOf : OffsetArrayOf } inline bool sanitize (SANITIZE_ARG_DEF) { - return OffsetArrayOf::sanitize (SANITIZE_ARG, (const char *) this); + return OffsetArrayOf::sanitize (SANITIZE_ARG, CONST_CHARP(this)); } }; diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 5c817db03..f43aa2de0 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -275,7 +275,7 @@ struct SinglePosFormat1 if (HB_LIKELY (index == NOT_COVERED)) return false; - valueFormat.apply_value (context, (const char *) this, values, CURPOSITION ()); + valueFormat.apply_value (context, CONST_CHARP(this), values, CURPOSITION ()); buffer->in_pos++; return true; @@ -308,7 +308,7 @@ struct SinglePosFormat2 if (HB_LIKELY (index >= valueCount)) return false; - valueFormat.apply_value (context, (const char *) this, + valueFormat.apply_value (context, CONST_CHARP(this), values + index * valueFormat.get_len (), CURPOSITION ()); @@ -413,8 +413,8 @@ struct PairPosFormat1 { if (IN_GLYPH (j) == record->secondGlyph) { - valueFormat1.apply_value (context, (const char *) this, record->values, CURPOSITION ()); - valueFormat2.apply_value (context, (const char *) this, record->values + len1, POSITION (j)); + valueFormat1.apply_value (context, CONST_CHARP(this), record->values, CURPOSITION ()); + valueFormat2.apply_value (context, CONST_CHARP(this), record->values + len1, POSITION (j)); if (len2) j++; buffer->in_pos = j; @@ -476,8 +476,8 @@ struct PairPosFormat2 return false; const Value *v = values + record_len * (klass1 * class2Count + klass2); - valueFormat1.apply_value (context, (const char *) this, v, CURPOSITION ()); - valueFormat2.apply_value (context, (const char *) this, v + len1, POSITION (j)); + valueFormat1.apply_value (context, CONST_CHARP(this), v, CURPOSITION ()); + valueFormat2.apply_value (context, CONST_CHARP(this), v + len1, POSITION (j)); if (len2) j++; diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 3e6c7e5be..e29128f14 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -568,17 +568,17 @@ struct ReverseChainSingleSubstFormat1 if (HB_LIKELY (index == NOT_COVERED)) return false; - const OffsetArrayOf &lookahead = (const OffsetArrayOf&) - *((const char *) &backtrack + backtrack.get_size ()); - const ArrayOf &substitute = (const ArrayOf&) - *((const char *) &lookahead + lookahead.get_size ()); + const OffsetArrayOf &lookahead = *(const OffsetArrayOf*) + (CONST_CHARP(&backtrack) + backtrack.get_size ()); + const ArrayOf &substitute = *(const ArrayOf*) + (CONST_CHARP(&lookahead) + lookahead.get_size ()); if (match_backtrack (APPLY_ARG, backtrack.len, (USHORT *) backtrack.array, - match_coverage, (char *) this) && + match_coverage, CHARP(this)) && match_lookahead (APPLY_ARG, lookahead.len, (USHORT *) lookahead.array, - match_coverage, (char *) this, + match_coverage, CHARP(this), 1)) { IN_CURGLYPH () = substitute[index]; @@ -592,12 +592,12 @@ struct ReverseChainSingleSubstFormat1 inline bool sanitize (SANITIZE_ARG_DEF) { if (!SANITIZE_THIS2 (coverage, backtrack)) return false; - OffsetArrayOf &lookahead = (OffsetArrayOf&) - *((const char *) &backtrack + backtrack.get_size ()); + OffsetArrayOf &lookahead = *(OffsetArrayOf*) + (CONST_CHARP(&backtrack) + backtrack.get_size ()); if (!SANITIZE_THIS (lookahead)) return false; - ArrayOf &substitute = (ArrayOf&) - *((const char *) &lookahead + lookahead.get_size ()); + ArrayOf &substitute = *(ArrayOf*) + (CONST_CHARP(&lookahead) + lookahead.get_size ()); if (!SANITIZE (substitute)) return false; } diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 792a7d78b..4324c93f6 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -257,7 +257,7 @@ struct Rule inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const { const LookupRecord *lookupRecord = (const LookupRecord *) - ((const char *) input + + (CONST_CHARP(input) + sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); return context_lookup (APPLY_ARG, inputCount, input, @@ -364,7 +364,7 @@ struct ContextFormat2 */ struct ContextLookupContext lookup_context = { {match_class, apply_func}, - (char *) &class_def + CHARP(&class_def) }; return rule_set.apply (APPLY_ARG, lookup_context); } @@ -400,11 +400,11 @@ struct ContextFormat3 return false; const LookupRecord *lookupRecord = (const LookupRecord *) - ((const char *) coverage + + (CONST_CHARP(coverage) + sizeof (coverage[0]) * glyphCount); struct ContextLookupContext lookup_context = { {match_coverage, apply_func}, - (char *) this + CHARP(this) }; return context_lookup (APPLY_ARG, glyphCount, (const USHORT *) (coverage + 1), @@ -418,7 +418,7 @@ struct ContextFormat3 for (unsigned int i = 0; i < count; i++) if (!SANITIZE_THIS (coverage[i])) return false; LookupRecord *lookupRecord = (LookupRecord *) - ((char *) coverage + + (CHARP(coverage) + sizeof (coverage[0]) * glyphCount); return SANITIZE_MEM (lookupRecord, sizeof (lookupRecord[0]) * lookupCount); } @@ -522,11 +522,11 @@ struct ChainRule inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const { const HeadlessArrayOf &input = *(const HeadlessArrayOf*) - ((const char *) &backtrack + backtrack.get_size ()); + (CONST_CHARP(&backtrack) + backtrack.get_size ()); const ArrayOf &lookahead = *(const ArrayOf*) - ((const char *) &input + input.get_size ()); + (CONST_CHARP(&input) + input.get_size ()); const ArrayOf &lookup = *(const ArrayOf*) - ((const char *) &lookahead + lookahead.get_size ()); + (CONST_CHARP(&lookahead) + lookahead.get_size ()); return chain_context_lookup (APPLY_ARG, backtrack.len, backtrack.array, input.len, input.array + 1, @@ -540,13 +540,13 @@ struct ChainRule inline bool sanitize (SANITIZE_ARG_DEF) { if (!SANITIZE (backtrack)) return false; HeadlessArrayOf &input = *(HeadlessArrayOf*) - ((char *) &backtrack + backtrack.get_size ()); + (CHARP(&backtrack) + backtrack.get_size ()); if (!SANITIZE (input)) return false; ArrayOf &lookahead = *(ArrayOf*) - ((char *) &input + input.get_size ()); + (CHARP(&input) + input.get_size ()); if (!SANITIZE (lookahead)) return false; ArrayOf &lookup = *(ArrayOf*) - ((char *) &lookahead + lookahead.get_size ()); + (CHARP(&lookahead) + lookahead.get_size ()); return SANITIZE (lookup); } @@ -648,9 +648,9 @@ struct ChainContextFormat2 */ struct ChainContextLookupContext lookup_context = { {match_class, apply_func}, - {(char *) &backtrack_class_def, - (char *) &input_class_def, - (char *) &lookahead_class_def} + {CHARP(&backtrack_class_def), + CHARP(&input_class_def), + CHARP(&lookahead_class_def)} }; return rule_set.apply (APPLY_ARG, lookup_context); } @@ -693,19 +693,19 @@ struct ChainContextFormat3 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { const OffsetArrayOf &input = *(const OffsetArrayOf*) - ((const char *) &backtrack + backtrack.get_size ()); + (CONST_CHARP(&backtrack) + backtrack.get_size ()); unsigned int index = (this+input[0]) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; const OffsetArrayOf &lookahead = *(const OffsetArrayOf*) - ((const char *) &input + input.get_size ()); + (CONST_CHARP(&input) + input.get_size ()); const ArrayOf &lookup = *(const ArrayOf*) - ((const char *) &lookahead + lookahead.get_size ()); + (CONST_CHARP(&lookahead) + lookahead.get_size ()); struct ChainContextLookupContext lookup_context = { {match_coverage, apply_func}, - {(char *) this, (char *) this, (char *) this} + {CHARP(this), CHARP(this), CHARP(this)} }; return chain_context_lookup (APPLY_ARG, backtrack.len, (USHORT *) backtrack.array, @@ -719,13 +719,13 @@ struct ChainContextFormat3 inline bool sanitize (SANITIZE_ARG_DEF) { if (!SANITIZE_THIS (backtrack)) return false; OffsetArrayOf &input = *(OffsetArrayOf*) - ((char *) &backtrack + backtrack.get_size ()); + (CHARP(&backtrack) + backtrack.get_size ()); if (!SANITIZE_THIS (input)) return false; OffsetArrayOf &lookahead = *(OffsetArrayOf*) - ((char *) &input + input.get_size ()); + (CHARP(&input) + input.get_size ()); if (!SANITIZE_THIS (lookahead)) return false; ArrayOf &lookup = *(ArrayOf*) - ((char *) &lookahead + lookahead.get_size ()); + (CHARP(&lookahead) + lookahead.get_size ()); return SANITIZE (lookup); } @@ -794,7 +794,7 @@ struct ExtensionFormat1 { unsigned int offset = get_offset (); if (HB_UNLIKELY (!offset)) return Null(LookupSubTable); - return *(LookupSubTable*)(((char *) this) + offset); + return *(LookupSubTable*)(CHARP(this) + offset); } inline bool sanitize (SANITIZE_ARG_DEF) {