Skip to content

Commit

Permalink
[buffer] In hb_buffer_get_positions(), return NULL if inside message …
Browse files Browse the repository at this point in the history
…callback

As discussed in #2468 (comment)

Part of fixing #2468
  • Loading branch information
behdad committed Jun 10, 2021
1 parent 855a3f4 commit c61ce96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/hb-buffer.cc
Expand Up @@ -1363,6 +1363,11 @@ hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
* Returns @buffer glyph position array. Returned pointer
* is valid as long as @buffer contents are not modified.
*
* If buffer did not have positions before, the positions will be
* initialized to zeros, unless this function is called from
* within a buffer message callback (see hb_buffer_set_message_func()),
* in which case %NULL is returned.
*
* Return value: (transfer none) (array length=length):
* The @buffer glyph position array.
* The value valid as long as buffer has not been modified.
Expand All @@ -1373,12 +1378,17 @@ hb_glyph_position_t *
hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
unsigned int *length)
{
if (!buffer->have_positions)
buffer->clear_positions ();

if (length)
*length = buffer->len;

if (!buffer->have_positions)
{
if (unlikely (buffer->message_depth))
return nullptr;

buffer->clear_positions ();
}

return (hb_glyph_position_t *) buffer->pos;
}

Expand Down
9 changes: 9 additions & 0 deletions src/hb-buffer.hh
Expand Up @@ -128,6 +128,9 @@ struct hb_buffer_t
hb_buffer_message_func_t message_func;
void *message_data;
hb_destroy_func_t message_destroy;
unsigned message_depth; /* How deeply are we inside a message callback? */
#else
static constexpr unsigned message_depth = 0u;
#endif

/* Internal debugging. */
Expand Down Expand Up @@ -400,10 +403,16 @@ struct hb_buffer_t
#else
if (!messaging ())
return true;

message_depth++;

va_list ap;
va_start (ap, fmt);
bool ret = message_impl (font, fmt, ap);
va_end (ap);

message_depth--;

return ret;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion util/options.cc
Expand Up @@ -454,7 +454,7 @@ shape_options_t::add_options (option_parser_t *parser)
{"cluster-level", 0, 0, G_OPTION_ARG_INT, &this->cluster_level, "Cluster merging level (default: 0)", "0/1/2"},
{"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", nullptr},
{"verify", 0, 0, G_OPTION_ARG_NONE, &this->verify, "Perform sanity checks on shaping results", nullptr},
{"num-iterations", 'n', 0, G_OPTION_ARG_INT, &this->num_iterations, "Run shaper N times (default: 1)", "N"},
{"num-iterations", 'n', 0, G_OPTION_ARG_INT, &this->num_iterations, "Run shaper N times (default: 1)", "N"},
{nullptr}
};
parser->add_group (entries,
Expand Down

0 comments on commit c61ce96

Please sign in to comment.