From a438ea62529ece4a9aedb915c7f350ca500c9d9f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 18 Jan 2025 13:49:04 -0700 Subject: [PATCH] [hvgl] Add IndexOf<> --- src/hb-aat-var-hvgl-table.hh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/hb-aat-var-hvgl-table.hh b/src/hb-aat-var-hvgl-table.hh index f95143016..f542858ab 100644 --- a/src/hb-aat-var-hvgl-table.hh +++ b/src/hb-aat-var-hvgl-table.hh @@ -395,6 +395,26 @@ struct Index DEFINE_SIZE_MIN (4); }; +template +struct IndexOf : Index +{ + public: + + Type get (unsigned index, unsigned count) const + { + hb_ubytes_t data = Index::get (index, count); + hb_sanitize_context_t c (data.begin (), data.end ()); + Type &item = *reinterpret_cast (data.begin ()); + if (unlikely (!item.sanitize (c))) return Null(Type); + return item; + } + + bool sanitize (hb_sanitize_context_t *c, unsigned count) const + { return Index::sanitize (c, count); } +}; + +using PartsIndex = IndexOf; + struct hvgl { public: @@ -405,7 +425,7 @@ struct hvgl if (unlikely (!c->check_struct (this))) return_trace (false); hb_barrier (); - const auto &parts = StructAtOffset (this, partsOff); + const auto &parts = StructAtOffset (this, partsOff); if (unlikely (!parts.sanitize (c, (unsigned) partCount))) return_trace (false); return_trace (true);