From 3f806673fbeacdbe1b31399394ccc26c773a794b Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sat, 29 Jun 2019 00:00:00 +0430 Subject: [PATCH] Apply some minor improves on CFFIndex --- src/hb-ot-cff-common.hh | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index e89fd1e0d..aced77c83 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -92,10 +92,8 @@ struct CFFIndex static unsigned int calculate_serialized_size (unsigned int offSize_, unsigned int count, unsigned int dataSize) { - if (count == 0) - return COUNT::static_size; - else - return min_size + calculate_offset_array_size (offSize_, count) + dataSize; + if (count == 0) return COUNT::static_size; + return min_size + calculate_offset_array_size (offSize_, count) + dataSize; } bool serialize (hb_serialize_context_t *c, const CFFIndex &src) @@ -159,9 +157,7 @@ struct CFFIndex byteArray.init (); byteArray.resize (buffArray.length); for (unsigned int i = 0; i < byteArray.length; i++) - { byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length); - } bool result = this->serialize (c, offSize_, byteArray); byteArray.fini (); return result; @@ -192,43 +188,35 @@ struct CFFIndex unsigned int length_at (unsigned int index) const { - if (likely ((offset_at (index + 1) >= offset_at (index)) && - (offset_at (index + 1) <= offset_at (count)))) - return offset_at (index + 1) - offset_at (index); - else + if (unlikely ((offset_at (index + 1) < offset_at (index)) || + (offset_at (index + 1) > offset_at (count)))) return 0; + return offset_at (index + 1) - offset_at (index); } const unsigned char *data_base () const - { return (const unsigned char *)this + min_size + offset_array_size (); } + { return (const unsigned char *) this + min_size + offset_array_size (); } unsigned int data_size () const { return HBINT8::static_size; } byte_str_t operator [] (unsigned int index) const { - if (likely (index < count)) - return byte_str_t (data_base () + offset_at (index) - 1, length_at (index)); - else - return Null (byte_str_t); + if (unlikely (index >= count)) return Null (byte_str_t); + return byte_str_t (data_base () + offset_at (index) - 1, length_at (index)); } unsigned int get_size () const { - if (this != &Null (CFFIndex)) - { - if (count > 0) - return min_size + offset_array_size () + (offset_at (count) - 1); - else - return count.static_size; /* empty CFFIndex contains count only */ - } - else - return 0; + if (this == &Null (CFFIndex)) return 0; + if (count > 0) + return min_size + offset_array_size () + (offset_at (count) - 1); + return count.static_size; /* empty CFFIndex contains count only */ } bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */ + return_trace (likely ((c->check_struct (this) && count == 0) || /* empty INDEX */ (c->check_struct (this) && offSize >= 1 && offSize <= 4 && c->check_array (offsets, offSize, count + 1) && c->check_array ((const HBUINT8*) data_base (), 1, max_offset () - 1))));