From a82ef7a893b773a17f7548375de9f588dfc83aba Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 May 2010 17:55:03 -0400 Subject: [PATCH] Remove CastP completely --- src/hb-open-type-private.hh | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index fcc8c80..45ed801 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -41,14 +41,6 @@ * Casts */ -/* Cast to "const char *" and "char *" */ -template -inline const char * CharP (const Type* X) -{ return reinterpret_cast(X); } -template -inline char * CharP (Type* X) -{ return reinterpret_cast(X); } - /* Cast to struct T, reference to reference */ template inline const Type& CastR(const TObject &X) @@ -69,10 +61,10 @@ inline Type* CastP(TObject *X) * location pointed to by P plus Ofs bytes. */ template inline const Type& StructAtOffset(const void *P, unsigned int offset) -{ return * reinterpret_cast (CharP(P) + offset); } +{ return * reinterpret_cast ((const char *) P + offset); } template inline Type& StructAtOffset(void *P, unsigned int offset) -{ return * reinterpret_cast (CharP(P) + offset); } +{ return * reinterpret_cast ((char *) P + offset); } /* StructAfter(X) returns the struct T& that is placed after X. * Works with X of variable size also. X must implement get_size() */ @@ -216,15 +208,16 @@ struct hb_sanitize_context_t 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; + const char *p = (const char *) base; + bool ret = this->start <= p && + p <= this->end && + (unsigned int) (this->end - p) >= len; if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE) \ fprintf (stderr, "SANITIZE(%p) %-*d-> range [%p..%p] (%d bytes) in [%p..%p] -> %s\n", \ - base, + p, this->debug_depth, this->debug_depth, - base, CharP(base) + len, len, + p, p + len, len, this->start, this->end, ret ? "pass" : "FAIL"); @@ -233,13 +226,14 @@ struct hb_sanitize_context_t inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const { + const char *p = (const char *) base; 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, + p, this->debug_depth, this->debug_depth, - base, CharP(base) + (record_size * len), record_size, len, (unsigned long) record_size * len, + p, p + (record_size * len), record_size, len, (unsigned long) record_size * len, this->start, this->end, !overflows ? "does not overflow" : "OVERFLOWS FAIL"); @@ -254,14 +248,15 @@ struct hb_sanitize_context_t inline bool can_edit (const void *base HB_UNUSED, unsigned int len HB_UNUSED) { + const char *p = (const char *) base; this->edit_count++; if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE) fprintf (stderr, "SANITIZE(%p) %-*d-> edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s\n", \ - base, + p, this->debug_depth, this->debug_depth, this->edit_count, - base, CharP(base)+len, len, + p, p + len, len, this->start, this->end, this->writable ? "granted" : "REJECTED"); @@ -389,7 +384,7 @@ struct IntType TRACE_SANITIZE (); return context->check_struct (this); } - private: + protected: BEInt v; public: DEFINE_SIZE_STATIC (sizeof (Type)); @@ -405,8 +400,8 @@ typedef IntType LONG; /* 32-bit signed integer. */ struct Tag : ULONG { /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ - inline operator const char* (void) const { return CharP(this); } - inline operator char* (void) { return CharP(this); } + inline operator const char* (void) const { return reinterpret_cast (&this->v); } + inline operator char* (void) { return reinterpret_cast (&this->v); } public: DEFINE_SIZE_STATIC (4); }; -- 2.7.4