[Hb] Use reinterpret casts instead of direct casts to char *

This commit is contained in:
Behdad Esfahbod 2009-08-04 11:04:32 -04:00
parent 92b5dd8e71
commit 196598bbcc
6 changed files with 57 additions and 50 deletions

View File

@ -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];
}
}

View File

@ -38,6 +38,13 @@
#define MAX_NESTING_LEVEL 8
/*
* Casts
*/
#define CONST_CHARP(X) (reinterpret_cast<const char *>(X))
#define CHARP(X) ((char *)reinterpret_cast<const char *>(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<const char *>(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<const char *>(B) && reinterpret_cast<const char *>(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<const char *>(this); }
inline operator char* (void) { return reinterpret_cast<char *>(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<const Type*>(reinterpret_cast<const char *>(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<Type*>((char *)(reinterpret_cast<const char *>(base) + offset))) || NEUTER (*this, 0);
}
};
template <typename Base, typename OffsetType, typename Type>

View File

@ -78,7 +78,7 @@ struct RecordListOf : RecordArrayOf<Type>
}
inline bool sanitize (SANITIZE_ARG_DEF) {
return RecordArrayOf<Type>::sanitize (SANITIZE_ARG, (const char *) this);
return RecordArrayOf<Type>::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<Type>
}
inline bool sanitize (SANITIZE_ARG_DEF) {
return OffsetArrayOf<Type>::sanitize (SANITIZE_ARG, (const char *) this);
return OffsetArrayOf<Type>::sanitize (SANITIZE_ARG, CONST_CHARP(this));
}
};

View File

@ -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++;

View File

@ -568,17 +568,17 @@ struct ReverseChainSingleSubstFormat1
if (HB_LIKELY (index == NOT_COVERED))
return false;
const OffsetArrayOf<Coverage> &lookahead = (const OffsetArrayOf<Coverage>&)
*((const char *) &backtrack + backtrack.get_size ());
const ArrayOf<GlyphID> &substitute = (const ArrayOf<GlyphID>&)
*((const char *) &lookahead + lookahead.get_size ());
const OffsetArrayOf<Coverage> &lookahead = *(const OffsetArrayOf<Coverage>*)
(CONST_CHARP(&backtrack) + backtrack.get_size ());
const ArrayOf<GlyphID> &substitute = *(const ArrayOf<GlyphID>*)
(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<Coverage> &lookahead = (OffsetArrayOf<Coverage>&)
*((const char *) &backtrack + backtrack.get_size ());
OffsetArrayOf<Coverage> &lookahead = *(OffsetArrayOf<Coverage>*)
(CONST_CHARP(&backtrack) + backtrack.get_size ());
if (!SANITIZE_THIS (lookahead))
return false;
ArrayOf<GlyphID> &substitute = (ArrayOf<GlyphID>&)
*((const char *) &lookahead + lookahead.get_size ());
ArrayOf<GlyphID> &substitute = *(ArrayOf<GlyphID>*)
(CONST_CHARP(&lookahead) + lookahead.get_size ());
if (!SANITIZE (substitute))
return false;
}

View File

@ -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<USHORT> &input = *(const HeadlessArrayOf<USHORT>*)
((const char *) &backtrack + backtrack.get_size ());
(CONST_CHARP(&backtrack) + backtrack.get_size ());
const ArrayOf<USHORT> &lookahead = *(const ArrayOf<USHORT>*)
((const char *) &input + input.get_size ());
(CONST_CHARP(&input) + input.get_size ());
const ArrayOf<LookupRecord> &lookup = *(const ArrayOf<LookupRecord>*)
((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<USHORT> &input = *(HeadlessArrayOf<USHORT>*)
((char *) &backtrack + backtrack.get_size ());
(CHARP(&backtrack) + backtrack.get_size ());
if (!SANITIZE (input)) return false;
ArrayOf<USHORT> &lookahead = *(ArrayOf<USHORT>*)
((char *) &input + input.get_size ());
(CHARP(&input) + input.get_size ());
if (!SANITIZE (lookahead)) return false;
ArrayOf<LookupRecord> &lookup = *(ArrayOf<LookupRecord>*)
((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<Coverage> &input = *(const OffsetArrayOf<Coverage>*)
((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<Coverage> &lookahead = *(const OffsetArrayOf<Coverage>*)
((const char *) &input + input.get_size ());
(CONST_CHARP(&input) + input.get_size ());
const ArrayOf<LookupRecord> &lookup = *(const ArrayOf<LookupRecord>*)
((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<Coverage> &input = *(OffsetArrayOf<Coverage>*)
((char *) &backtrack + backtrack.get_size ());
(CHARP(&backtrack) + backtrack.get_size ());
if (!SANITIZE_THIS (input)) return false;
OffsetArrayOf<Coverage> &lookahead = *(OffsetArrayOf<Coverage>*)
((char *) &input + input.get_size ());
(CHARP(&input) + input.get_size ());
if (!SANITIZE_THIS (lookahead)) return false;
ArrayOf<LookupRecord> &lookup = *(ArrayOf<LookupRecord>*)
((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) {