Skip to content

Commit

Permalink
Add hb_addressof() and use it to fix bug after hb_bytes_t merge
Browse files Browse the repository at this point in the history
We cannot take address hb_bytes_t direction.  We need to use the
newly added hb_addressof(), ala std::addressof().
  • Loading branch information
behdad committed Dec 18, 2018
1 parent 49334f9 commit 8d2d410
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/hb-dsalgs.hh
Expand Up @@ -234,6 +234,15 @@ hb_ctz (T v)
* Tiny stuff.
*/

template <typename T>
T* hb_addressof (T& arg)
{
/* https://en.cppreference.com/w/cpp/memory/addressof */
return reinterpret_cast<T*>(
&const_cast<char&>(
reinterpret_cast<const volatile char&>(arg)));
}

/* ASCII tag/character handling */
static inline bool ISALPHA (unsigned char c)
{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
Expand Down
3 changes: 2 additions & 1 deletion src/hb-ot-post-table.hh
Expand Up @@ -168,7 +168,8 @@ struct post
}

hb_bytes_t st (name, len);
const uint16_t *gid = (const uint16_t *) hb_bsearch_r (&st, gids, count, sizeof (gids[0]), cmp_key, (void *) this);
const uint16_t *gid = (const uint16_t *) hb_bsearch_r (hb_addressof (st), gids, count,
sizeof (gids[0]), cmp_key, (void *) this);
if (gid)
{
*glyph = *gid;
Expand Down

0 comments on commit 8d2d410

Please sign in to comment.