From 11e3ec444a85fc72541823c2e98cc92c4ceb19af Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 3 Nov 2010 15:11:04 -0400 Subject: [PATCH] Fix a few more "unreachable code" warnings --- src/hb-blob.c | 2 +- src/hb-object-private.h | 12 +++--- src/hb-open-type-private.hh | 84 +++++++++++++++++------------------- src/hb-ot-layout-gsubgpos-private.hh | 2 +- src/hb-private.h | 3 +- 5 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/hb-blob.c b/src/hb-blob.c index 926481d..3c98052 100644 --- a/src/hb-blob.c +++ b/src/hb-blob.c @@ -42,7 +42,7 @@ HB_BEGIN_DECLS #ifndef HB_DEBUG_BLOB -#define HB_DEBUG_BLOB HB_DEBUG+0 +#define HB_DEBUG_BLOB (HB_DEBUG+0) #endif hb_blob_t _hb_blob_nil = { diff --git a/src/hb-object-private.h b/src/hb-object-private.h index 57f5f94..4e98a95 100644 --- a/src/hb-object-private.h +++ b/src/hb-object-private.h @@ -60,7 +60,7 @@ typedef struct { /* Debug */ #ifndef HB_DEBUG_OBJECT -#define HB_DEBUG_OBJECT HB_DEBUG+0 +#define HB_DEBUG_OBJECT (HB_DEBUG+0) #endif static inline void @@ -68,11 +68,11 @@ _hb_trace_object (const void *obj, hb_reference_count_t *ref_count, const char *function) { - if (HB_DEBUG_OBJECT) - fprintf (stderr, "OBJECT(%p) refcount=%d %s\n", - obj, - HB_REFERENCE_COUNT_GET_VALUE (*ref_count), - function); + (void) (HB_DEBUG_OBJECT && + fprintf (stderr, "OBJECT(%p) refcount=%d %s\n", + obj, + HB_REFERENCE_COUNT_GET_VALUE (*ref_count), + function)); } #define TRACE_OBJECT(obj) _hb_trace_object (obj, &obj->ref_count, __FUNCTION__) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 38ba3a3..8f3001b 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -152,8 +152,8 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) template struct hb_trace_t { explicit hb_trace_t (unsigned int *pdepth, const char *what, const char *function, const void *obj) : pdepth(pdepth) { - if (*pdepth < max_depth) - fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, *pdepth, *pdepth, function); + (void) (*pdepth < max_depth && + fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, *pdepth, *pdepth, function)); if (max_depth) ++*pdepth; } ~hb_trace_t (void) { if (max_depth) --*pdepth; } @@ -173,7 +173,7 @@ struct hb_trace_t<0> { */ #ifndef HB_DEBUG_SANITIZE -#define HB_DEBUG_SANITIZE HB_DEBUG+0 +#define HB_DEBUG_SANITIZE (HB_DEBUG+0) #endif @@ -192,17 +192,17 @@ struct hb_sanitize_context_t this->edit_count = 0; this->debug_depth = 0; - if (HB_DEBUG_SANITIZE) + (void) (HB_DEBUG_SANITIZE && fprintf (stderr, "sanitize %p init [%p..%p] (%lu bytes)\n", this->blob, this->start, this->end, - (unsigned long) (this->end - this->start)); + (unsigned long) (this->end - this->start))); } inline void finish (void) { - if (HB_DEBUG_SANITIZE) + (void) (HB_DEBUG_SANITIZE && fprintf (stderr, "sanitize %p fini [%p..%p] %u edit requests\n", - this->blob, this->start, this->end, this->edit_count); + this->blob, this->start, this->end, this->edit_count)); hb_blob_unlock (this->blob); hb_blob_destroy (this->blob); @@ -217,13 +217,13 @@ struct hb_sanitize_context_t 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", \ + (void) (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", p, this->debug_depth, this->debug_depth, p, p + len, len, this->start, this->end, - ret ? "pass" : "FAIL"); + ret ? "pass" : "FAIL")); return likely (ret); } @@ -233,13 +233,13 @@ struct hb_sanitize_context_t const char *p = (const char *) base; bool overflows = record_size > 0 && 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", \ + (void) (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", p, this->debug_depth, this->debug_depth, p, p + (record_size * len), record_size, len, (unsigned long) record_size * len, this->start, this->end, - !overflows ? "does not overflow" : "OVERFLOWS FAIL"); + !overflows ? "does not overflow" : "OVERFLOWS FAIL")); return likely (!overflows && this->check_range (base, record_size * len)); } @@ -255,14 +255,14 @@ struct hb_sanitize_context_t 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", \ + (void) (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", p, this->debug_depth, this->debug_depth, this->edit_count, p, p + len, len, this->start, this->end, - this->writable ? "granted" : "REJECTED"); + this->writable ? "granted" : "REJECTED")); return this->writable; } @@ -290,8 +290,8 @@ struct Sanitizer return hb_blob_create_empty (); retry: - if (HB_DEBUG_SANITIZE) - fprintf (stderr, "Sanitizer %p start %s\n", blob, HB_FUNC); + (void) (HB_DEBUG_SANITIZE && + fprintf (stderr, "Sanitizer %p start %s\n", blob, HB_FUNC)); c->init (blob); @@ -305,17 +305,17 @@ struct Sanitizer sane = t->sanitize (c); if (sane) { if (c->edit_count) { - if (HB_DEBUG_SANITIZE) + (void) (HB_DEBUG_SANITIZE && fprintf (stderr, "Sanitizer %p passed first round with %d edits; doing a second round %s\n", - blob, c->edit_count, HB_FUNC); + blob, c->edit_count, HB_FUNC)); /* sanitize again to ensure no toe-stepping */ c->edit_count = 0; sane = t->sanitize (c); if (c->edit_count) { - if (HB_DEBUG_SANITIZE) + (void) (HB_DEBUG_SANITIZE && fprintf (stderr, "Sanitizer %p requested %d edits in second round; FAILLING %s\n", - blob, c->edit_count, HB_FUNC); + blob, c->edit_count, HB_FUNC)); sane = false; } } @@ -325,14 +325,14 @@ struct Sanitizer c->finish (); if (edit_count && !hb_blob_is_writable (blob) && hb_blob_try_writable (blob)) { /* ok, we made it writable by relocating. try again */ - if (HB_DEBUG_SANITIZE) - fprintf (stderr, "Sanitizer %p retry %s\n", blob, HB_FUNC); + (void) (HB_DEBUG_SANITIZE && + fprintf (stderr, "Sanitizer %p retry %s\n", blob, HB_FUNC)); goto retry; } } - if (HB_DEBUG_SANITIZE) - fprintf (stderr, "Sanitizer %p %s %s\n", blob, sane ? "passed" : "FAILED", HB_FUNC); + (void) (HB_DEBUG_SANITIZE && + fprintf (stderr, "Sanitizer %p %s %s\n", blob, sane ? "passed" : "FAILED", HB_FUNC)); if (sane) return blob; else { @@ -577,18 +577,16 @@ struct GenericArrayOf inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); if (unlikely (!sanitize_shallow (c))) return false; + /* Note: for structs that do not reference other structs, * we do not need to call their sanitize() as we already did - * a bound check on the aggregate array size, hence the return. + * a bound check on the aggregate array size. We just include + * a small unreachable expression to make sure the structs + * pointed to do have a simple sanitize(), ie. they do not + * reference other structs via offsets. */ - return true; - /* We do keep this code though to make sure the structs pointed - * to do have a simple sanitize(), ie. they do not reference - * other structs. */ - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (unlikely (!array[i].sanitize (c))) - return false; + (void) (false && array[0].sanitize (c)); + return true; } inline bool sanitize (hb_sanitize_context_t *c, void *base) { @@ -688,18 +686,16 @@ struct HeadlessArrayOf inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); if (unlikely (!sanitize_shallow (c))) return false; + /* Note: for structs that do not reference other structs, * we do not need to call their sanitize() as we already did - * a bound check on the aggregate array size, hence the return. + * a bound check on the aggregate array size. We just include + * a small unreachable expression to make sure the structs + * pointed to do have a simple sanitize(), ie. they do not + * reference other structs via offsets. */ - return true; - /* We do keep this code though to make sure the structs pointed - * to do have a simple sanitize(), ie. they do not reference - * other structs. */ - unsigned int count = len ? len - 1 : 0; - for (unsigned int i = 0; i < count; i++) - if (unlikely (!array[i].sanitize (c))) - return false; + (void) (false && array[0].sanitize (c)); + return true; } diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index b99941e..caba1cf 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -41,7 +41,7 @@ HB_BEGIN_DECLS #ifndef HB_DEBUG_APPLY -#define HB_DEBUG_APPLY HB_DEBUG+0 +#define HB_DEBUG_APPLY (HB_DEBUG+0) #endif #define TRACE_APPLY() \ diff --git a/src/hb-private.h b/src/hb-private.h index 1d4cfc9..96b9464 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -257,8 +257,7 @@ _hb_trace (const char *what, unsigned int depth, unsigned int max_depth) { - if (depth < max_depth) - fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, depth, depth, function); + (void) ((depth < max_depth) && fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, depth, depth, function)); return TRUE; } -- 2.7.4