[buffer] HB_NODISCARD ensure()

pull/2900/head
Behdad Esfahbod 4 years ago
parent d8028a0762
commit 05d2d37f9a
  1. 7
      src/hb-buffer.cc
  2. 2
      src/hb-buffer.hh
  3. 2
      src/hb-graphite2.cc

@ -1318,7 +1318,7 @@ hb_buffer_set_length (hb_buffer_t *buffer,
if (unlikely (hb_object_is_immutable (buffer)))
return length == 0;
if (!buffer->ensure (length))
if (unlikely (!buffer->ensure (length)))
return false;
/* Wipe the new space */
@ -1548,7 +1548,10 @@ hb_buffer_add_utf (hb_buffer_t *buffer,
if (item_length == -1)
item_length = text_length - item_offset;
buffer->ensure (buffer->len + item_length * sizeof (T) / 4);
if (unlikely (item_length < 0 ||
item_length > INT_MAX / 8 ||
!buffer->ensure (buffer->len + item_length * sizeof (T) / 4)))
return;
/* If buffer is empty and pre-context provided, install it.
* This check is written this way, to make sure people can

@ -337,7 +337,7 @@ struct hb_buffer_t
HB_INTERNAL HB_NODISCARD bool enlarge (unsigned int size);
bool ensure (unsigned int size)
HB_NODISCARD bool ensure (unsigned int size)
{ return likely (!size || size < allocated) ? true : enlarge (size); }
bool ensure_inplace (unsigned int size)

@ -289,7 +289,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
return true;
}
buffer->ensure (glyph_count);
(void) buffer->ensure (glyph_count);
scratch = buffer->get_scratch_buffer (&scratch_size);
while ((DIV_CEIL (sizeof (hb_graphite2_cluster_t) * buffer->len, sizeof (*scratch)) +
DIV_CEIL (sizeof (hb_codepoint_t) * glyph_count, sizeof (*scratch))) > scratch_size)

Loading…
Cancel
Save