Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[dwrite] Don't allocate more than needed
Addressing Nikolay Sivov reviews on harfbuzz mailing list
  • Loading branch information
ebraminio committed Jun 26, 2016
commit 8179ff5d7ba4a140cf6743729a22072800e98a79
15 changes: 6 additions & 9 deletions src/hb-directwrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
(const DWRITE_TYPOGRAPHIC_FEATURES*) &singleFeatures;
const uint32_t featureRangeLengths[] = { textLength };

uint16_t* clusterMap = (uint16_t*) malloc (textLength * sizeof (uint16_t));
DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
malloc (textLength * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES));
retry_getglyphs:
uint16_t* clusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t));
uint16_t* glyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t));
DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
malloc (maxGlyphCount * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES));
DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
malloc (maxGlyphCount * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES));

Expand All @@ -679,9 +679,7 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,

if (unlikely (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)))
{
free (clusterMap);
free (glyphIndices);
free (textProperties);
free (glyphProperties);

maxGlyphCount *= 2;
Expand Down Expand Up @@ -779,10 +777,10 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
// if a script justificationCharacter is not space, it can have GetJustifiedGlyphs
if (justificationCharacter != 32)
{
uint16_t* modifiedClusterMap = (uint16_t*) malloc (textLength * sizeof (uint16_t));
retry_getjustifiedglyphs:
uint16_t* modifiedClusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t));
float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof(float));
uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t));
float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof (float));
DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*)
malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET));
uint32_t actualGlyphsCount;
Expand All @@ -795,7 +793,6 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))
{
maxGlyphCount = actualGlyphsCount;
free (modifiedClusterMap);
free (modifiedGlyphIndices);
free (modifiedGlyphAdvances);
free (modifiedGlyphOffsets);
Expand Down