Index: third_party/harfbuzz-ng/src/hb-graphite2.cc |
diff --git a/third_party/harfbuzz-ng/src/hb-graphite2.cc b/third_party/harfbuzz-ng/src/hb-graphite2.cc |
index cce860694ccfeca186bc3d5ed2f86920297073ed..60d68d6b57a6aa69d65ec11940315524bbafaa81 100644 |
--- a/third_party/harfbuzz-ng/src/hb-graphite2.cc |
+++ b/third_party/harfbuzz-ng/src/hb-graphite2.cc |
@@ -30,11 +30,10 @@ |
#define hb_graphite2_shaper_font_data_t gr_font |
#include "hb-shaper-impl-private.hh" |
-#include <graphite2/Font.h> |
-#include <graphite2/Segment.h> |
- |
#include "hb-graphite2.h" |
+#include <graphite2/Segment.h> |
+ |
#include "hb-ot-tag.h" |
@@ -244,14 +243,9 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, |
float curradvx = 0., curradvy = 0.; |
unsigned int scratch_size; |
- char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); |
- |
-#define ALLOCATE_ARRAY(Type, name, len) \ |
- Type *name = (Type *) scratch; \ |
- scratch += (len) * sizeof ((name)[0]); \ |
- scratch_size -= (len) * sizeof ((name)[0]); |
+ hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); |
- ALLOCATE_ARRAY (uint32_t, chars, buffer->len); |
+ uint32_t *chars = (uint32_t *) scratch; |
for (unsigned int i = 0; i < buffer->len; ++i) |
chars[i] = buffer->info[i].codepoint; |
@@ -277,9 +271,9 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, |
return false; |
} |
- scratch = (char *) buffer->get_scratch_buffer (&scratch_size); |
- while ((sizeof (hb_graphite2_cluster_t) * buffer->len + |
- sizeof (hb_codepoint_t) * glyph_count) > scratch_size) |
+ 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) |
{ |
buffer->ensure (buffer->allocated * 2); |
if (unlikely (buffer->in_error)) { |
@@ -287,12 +281,23 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, |
gr_seg_destroy (seg); |
return false; |
} |
- scratch = (char *) buffer->get_scratch_buffer (&scratch_size); |
+ scratch = buffer->get_scratch_buffer (&scratch_size); |
+ } |
+ |
+#define ALLOCATE_ARRAY(Type, name, len) \ |
+ Type *name = (Type *) scratch; \ |
+ { \ |
+ unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \ |
+ assert (_consumed <= scratch_size); \ |
+ scratch += _consumed; \ |
+ scratch_size -= _consumed; \ |
} |
ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); |
ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); |
+#undef ALLOCATE_ARRAY |
+ |
memset (clusters, 0, sizeof (clusters[0]) * buffer->len); |
hb_codepoint_t *pg = gids; |