Improve blob->as<>
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 31 Oct 2018 20:19:42 +0000 (13:19 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 31 Oct 2018 20:19:42 +0000 (13:19 -0700)
It's true that blob->as<> should only be called on null or sanitized
data.  But this change is safe, so keep it.

src/hb-blob.hh
src/hb-ot-glyf-table.hh

index 26e2dd7..0181e94 100644 (file)
@@ -60,7 +60,7 @@ struct hb_blob_t
   template <typename Type>
   inline const Type* as (void) const
   {
-    return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data);
+    return length < Type::min_size ? &Null(Type) : reinterpret_cast<const Type *> (data);
   }
   inline hb_bytes_t as_bytes (void) const
   {
index 9437a83..7bd175e 100644 (file)
@@ -55,6 +55,7 @@ struct loca
 
   protected:
   UnsizedArrayOf<HBUINT8>      dataZ;          /* Location data. */
+  public:
   DEFINE_SIZE_ARRAY (0, dataZ);
 };
 
@@ -484,7 +485,7 @@ struct glyf
 
   protected:
   UnsizedArrayOf<HBUINT8>      dataZ;          /* Glyphs data. */
-
+  public:
   DEFINE_SIZE_ARRAY (0, dataZ);
 };