dwrite: Use more appropriate allocation helpers.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2019-02-13 10:47:10 +03:00 committed by Alexandre Julliard
parent 35b01d6205
commit 8d2e59edaa
5 changed files with 42 additions and 41 deletions

View File

@ -448,7 +448,7 @@ static HRESULT analyze_linebreaks(const WCHAR *text, UINT32 count, DWRITE_LINE_B
short *break_class; short *break_class;
int i, j; int i, j;
break_class = heap_alloc(count*sizeof(short)); break_class = heap_calloc(count, sizeof(*break_class));
if (!break_class) if (!break_class)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -937,8 +937,8 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer2 *iface
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
levels = heap_alloc(length*sizeof(*levels)); levels = heap_calloc(length, sizeof(*levels));
explicit = heap_alloc(length*sizeof(*explicit)); explicit = heap_calloc(length, sizeof(*explicit));
if (!levels || !explicit) { if (!levels || !explicit) {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
@ -1013,7 +1013,7 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnaly
if (len < length) { if (len < length) {
UINT32 read; UINT32 read;
buff = heap_alloc(length*sizeof(WCHAR)); buff = heap_calloc(length, sizeof(*buff));
if (!buff) if (!buff)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memcpy(buff, text, len*sizeof(WCHAR)); memcpy(buff, text, len*sizeof(WCHAR));
@ -1032,7 +1032,7 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnaly
text = buff; text = buff;
} }
breakpoints = heap_alloc(length*sizeof(*breakpoints)); breakpoints = heap_calloc(length, sizeof(*breakpoints));
if (!breakpoints) { if (!breakpoints) {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto done; goto done;
@ -1176,7 +1176,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer2 *iface,
if (max_glyph_count < length) if (max_glyph_count < length)
return E_NOT_SUFFICIENT_BUFFER; return E_NOT_SUFFICIENT_BUFFER;
string = heap_alloc(sizeof(WCHAR)*length); string = heap_calloc(length, sizeof(*string));
if (!string) if (!string)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -1432,7 +1432,7 @@ static HRESULT apply_cluster_spacing(float leading_spacing, float trailing_spaci
break; break;
} }
deltas = heap_alloc((end - start + 1) * sizeof(*deltas)); deltas = heap_calloc(end - start + 1, sizeof(*deltas));
if (!deltas) if (!deltas)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -1677,7 +1677,7 @@ static HRESULT WINAPI dwritetextanalyzer1_GetTextComplexity(IDWriteTextAnalyzer2
/* fetch indices */ /* fetch indices */
if (*is_simple && indices) { if (*is_simple && indices) {
UINT32 *codepoints = heap_alloc(*len_read*sizeof(UINT32)); UINT32 *codepoints = heap_calloc(*len_read, sizeof(*codepoints));
if (!codepoints) if (!codepoints)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -2305,7 +2305,7 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder
struct fallback_mapping *mappings; struct fallback_mapping *mappings;
if (fallbackbuilder->mappings_capacity == 0) { if (fallbackbuilder->mappings_capacity == 0) {
if ((mappings = heap_alloc(sizeof(*fallbackbuilder->mappings) * 16))) if ((mappings = heap_calloc(16, sizeof(*mappings))))
fallbackbuilder->mappings_capacity = 16; fallbackbuilder->mappings_capacity = 16;
} }
else { else {
@ -2321,7 +2321,7 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder
mapping = &fallbackbuilder->mappings[fallbackbuilder->mappings_count++]; mapping = &fallbackbuilder->mappings[fallbackbuilder->mappings_count++];
mapping->ranges = heap_alloc(sizeof(*mapping->ranges) * ranges_count); mapping->ranges = heap_calloc(ranges_count, sizeof(*mapping->ranges));
memcpy(mapping->ranges, ranges, sizeof(*mapping->ranges) * ranges_count); memcpy(mapping->ranges, ranges, sizeof(*mapping->ranges) * ranges_count);
mapping->ranges_count = ranges_count; mapping->ranges_count = ranges_count;
mapping->families = heap_alloc_zero(sizeof(*mapping->families) * families_count); mapping->families = heap_alloc_zero(sizeof(*mapping->families) * families_count);

View File

@ -964,7 +964,7 @@ static HRESULT bidi_compute_isolating_runs_set(UINT8 baselevel, UINT8 *classes,
HRESULT hr = S_OK; HRESULT hr = S_OK;
Run *runs; Run *runs;
runs = heap_alloc(count * sizeof(Run)); runs = heap_calloc(count, sizeof(*runs));
if (!runs) if (!runs)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;

View File

@ -2227,7 +2227,7 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily1 *ifac
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
/* Allocate as many as family has, not all of them will be necessary used. */ /* Allocate as many as family has, not all of them will be necessary used. */
fonts->fonts = heap_alloc(sizeof(*fonts->fonts) * This->data->font_count); fonts->fonts = heap_calloc(This->data->font_count, sizeof(*fonts->fonts));
if (!fonts->fonts) { if (!fonts->fonts) {
heap_free(fonts); heap_free(fonts);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -2718,7 +2718,7 @@ static HRESULT init_font_collection(struct dwrite_fontcollection *collection, BO
collection->ref = 1; collection->ref = 1;
collection->family_count = 0; collection->family_count = 0;
collection->family_alloc = is_system ? 30 : 5; collection->family_alloc = is_system ? 30 : 5;
collection->family_data = heap_alloc(sizeof(*collection->family_data) * collection->family_alloc); collection->family_data = heap_calloc(collection->family_alloc, sizeof(*collection->family_data));
if (!collection->family_data) if (!collection->family_data)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -3567,7 +3567,7 @@ static HRESULT init_fontfamily_data(IDWriteLocalizedStrings *familyname, struct
data->has_oblique_face = 0; data->has_oblique_face = 0;
data->has_italic_face = 0; data->has_italic_face = 0;
data->fonts = heap_alloc(sizeof(*data->fonts)*data->font_alloc); data->fonts = heap_calloc(data->font_alloc, sizeof(*data->fonts));
if (!data->fonts) { if (!data->fonts) {
heap_free(data); heap_free(data);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -5475,8 +5475,8 @@ HRESULT create_glyphrunanalysis(const struct glyphrunanalysis_desc *desc, IDWrit
SetRectEmpty(&analysis->bounds); SetRectEmpty(&analysis->bounds);
analysis->run = *desc->run; analysis->run = *desc->run;
IDWriteFontFace_AddRef(analysis->run.fontFace); IDWriteFontFace_AddRef(analysis->run.fontFace);
analysis->glyphs = heap_alloc(desc->run->glyphCount * sizeof(*analysis->glyphs)); analysis->glyphs = heap_calloc(desc->run->glyphCount, sizeof(*analysis->glyphs));
analysis->origins = heap_alloc(desc->run->glyphCount * sizeof(*analysis->origins)); analysis->origins = heap_calloc(desc->run->glyphCount, sizeof(*analysis->origins));
if (!analysis->glyphs || !analysis->origins) { if (!analysis->glyphs || !analysis->origins) {
heap_free(analysis->glyphs); heap_free(analysis->glyphs);
@ -5814,12 +5814,12 @@ HRESULT create_colorglyphenum(float originX, float originY, const DWRITE_GLYPH_R
return DWRITE_E_NOCOLOR; return DWRITE_E_NOCOLOR;
} }
colorglyphenum->advances = heap_alloc(run->glyphCount * sizeof(FLOAT)); colorglyphenum->advances = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->advances));
colorglyphenum->color_advances = heap_alloc(run->glyphCount * sizeof(FLOAT)); colorglyphenum->color_advances = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->color_advances));
colorglyphenum->glyphindices = heap_alloc(run->glyphCount * sizeof(UINT16)); colorglyphenum->glyphindices = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->glyphindices));
if (run->glyphOffsets) { if (run->glyphOffsets) {
colorglyphenum->offsets = heap_alloc(run->glyphCount * sizeof(*colorglyphenum->offsets)); colorglyphenum->offsets = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->offsets));
colorglyphenum->color_offsets = heap_alloc(run->glyphCount * sizeof(*colorglyphenum->color_offsets)); colorglyphenum->color_offsets = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->color_offsets));
memcpy(colorglyphenum->offsets, run->glyphOffsets, run->glyphCount * sizeof(*run->glyphOffsets)); memcpy(colorglyphenum->offsets, run->glyphOffsets, run->glyphCount * sizeof(*run->glyphOffsets));
} }
@ -6311,7 +6311,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
} }
else { else {
loader->capacity = 16; loader->capacity = 16;
loader->streams = heap_alloc(loader->capacity * sizeof(*loader->streams)); loader->streams = heap_calloc(loader->capacity, sizeof(*loader->streams));
} }
} }

View File

@ -594,7 +594,7 @@ static HRESULT layout_update_breakpoints_range(struct dwrite_textlayout *layout,
after = before = DWRITE_BREAK_CONDITION_NEUTRAL; after = before = DWRITE_BREAK_CONDITION_NEUTRAL;
if (!layout->actual_breakpoints) { if (!layout->actual_breakpoints) {
layout->actual_breakpoints = heap_alloc(sizeof(DWRITE_LINE_BREAKPOINT)*layout->len); layout->actual_breakpoints = heap_calloc(layout->len, sizeof(*layout->actual_breakpoints));
if (!layout->actual_breakpoints) if (!layout->actual_breakpoints)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memcpy(layout->actual_breakpoints, layout->nominal_breakpoints, sizeof(DWRITE_LINE_BREAKPOINT)*layout->len); memcpy(layout->actual_breakpoints, layout->nominal_breakpoints, sizeof(DWRITE_LINE_BREAKPOINT)*layout->len);
@ -933,15 +933,15 @@ static HRESULT layout_shape_run(struct dwrite_textlayout *layout, struct regular
range = get_layout_range_by_pos(layout, run->descr.textPosition); range = get_layout_range_by_pos(layout, run->descr.textPosition);
run->descr.localeName = range->locale; run->descr.localeName = range->locale;
run->clustermap = heap_alloc(run->descr.stringLength * sizeof(*run->clustermap)); run->clustermap = heap_calloc(run->descr.stringLength, sizeof(*run->clustermap));
max_count = 3 * run->descr.stringLength / 2 + 16; max_count = 3 * run->descr.stringLength / 2 + 16;
run->glyphs = heap_alloc(max_count * sizeof(*run->glyphs)); run->glyphs = heap_calloc(max_count, sizeof(*run->glyphs));
if (!run->clustermap || !run->glyphs) if (!run->clustermap || !run->glyphs)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
text_props = heap_alloc(run->descr.stringLength * sizeof(*text_props)); text_props = heap_calloc(run->descr.stringLength, sizeof(*text_props));
glyph_props = heap_alloc(max_count * sizeof(*glyph_props)); glyph_props = heap_calloc(max_count, sizeof(*glyph_props));
if (!text_props || !glyph_props) { if (!text_props || !glyph_props) {
heap_free(text_props); heap_free(text_props);
heap_free(glyph_props); heap_free(glyph_props);
@ -960,8 +960,8 @@ static HRESULT layout_shape_run(struct dwrite_textlayout *layout, struct regular
max_count = run->glyphcount; max_count = run->glyphcount;
run->glyphs = heap_alloc(max_count * sizeof(*run->glyphs)); run->glyphs = heap_calloc(max_count, sizeof(*run->glyphs));
glyph_props = heap_alloc(max_count * sizeof(*glyph_props)); glyph_props = heap_calloc(max_count, sizeof(*glyph_props));
if (!run->glyphs || !glyph_props) { if (!run->glyphs || !glyph_props) {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
break; break;
@ -983,8 +983,8 @@ static HRESULT layout_shape_run(struct dwrite_textlayout *layout, struct regular
run->run.glyphIndices = run->glyphs; run->run.glyphIndices = run->glyphs;
run->descr.clusterMap = run->clustermap; run->descr.clusterMap = run->clustermap;
run->advances = heap_alloc(run->glyphcount * sizeof(*run->advances)); run->advances = heap_calloc(run->glyphcount, sizeof(*run->advances));
run->offsets = heap_alloc(run->glyphcount * sizeof(*run->offsets)); run->offsets = heap_calloc(run->glyphcount, sizeof(*run->offsets));
if (!run->advances || !run->offsets) if (!run->advances || !run->offsets)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -1034,8 +1034,8 @@ static HRESULT layout_compute_runs(struct dwrite_textlayout *layout)
/* Cluster data arrays are allocated once, assuming one text position per cluster. */ /* Cluster data arrays are allocated once, assuming one text position per cluster. */
if (!layout->clustermetrics && layout->len) { if (!layout->clustermetrics && layout->len) {
layout->clustermetrics = heap_alloc(layout->len*sizeof(*layout->clustermetrics)); layout->clustermetrics = heap_calloc(layout->len, sizeof(*layout->clustermetrics));
layout->clusters = heap_alloc(layout->len*sizeof(*layout->clusters)); layout->clusters = heap_calloc(layout->len, sizeof(*layout->clusters));
if (!layout->clustermetrics || !layout->clusters) { if (!layout->clustermetrics || !layout->clusters) {
heap_free(layout->clustermetrics); heap_free(layout->clustermetrics);
heap_free(layout->clusters); heap_free(layout->clusters);
@ -1122,7 +1122,7 @@ static HRESULT layout_compute(struct dwrite_textlayout *layout)
if (!layout->nominal_breakpoints) { if (!layout->nominal_breakpoints) {
IDWriteTextAnalyzer *analyzer; IDWriteTextAnalyzer *analyzer;
layout->nominal_breakpoints = heap_alloc(layout->len * sizeof(*layout->nominal_breakpoints)); layout->nominal_breakpoints = heap_calloc(layout->len, sizeof(*layout->nominal_breakpoints));
if (!layout->nominal_breakpoints) if (!layout->nominal_breakpoints)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -1291,7 +1291,7 @@ static HRESULT layout_add_effective_run(struct dwrite_textlayout *layout, const
length = layout->clusters[last_cluster].position - layout->clusters[first_cluster].position + length = layout->clusters[last_cluster].position - layout->clusters[first_cluster].position +
layout->clustermetrics[last_cluster].length; layout->clustermetrics[last_cluster].length;
run->clustermap = heap_alloc(sizeof(UINT16)*length); run->clustermap = heap_calloc(length, sizeof(*run->clustermap));
if (!run->clustermap) { if (!run->clustermap) {
heap_free(run); heap_free(run);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -1386,8 +1386,8 @@ static HRESULT layout_set_line_metrics(struct dwrite_textlayout *layout, DWRITE_
if (!layout->line_alloc) { if (!layout->line_alloc) {
layout->line_alloc = 5; layout->line_alloc = 5;
layout->linemetrics = heap_alloc(layout->line_alloc * sizeof(*layout->linemetrics)); layout->linemetrics = heap_calloc(layout->line_alloc, sizeof(*layout->linemetrics));
layout->lines = heap_alloc(layout->line_alloc * sizeof(*layout->lines)); layout->lines = heap_calloc(layout->line_alloc, sizeof(*layout->lines));
if (!layout->linemetrics || !layout->lines) { if (!layout->linemetrics || !layout->lines) {
heap_free(layout->linemetrics); heap_free(layout->linemetrics);
heap_free(layout->lines); heap_free(layout->lines);
@ -5787,7 +5787,7 @@ HRESULT create_typography(IDWriteTypography **ret)
typography->allocated = 2; typography->allocated = 2;
typography->count = 0; typography->count = 0;
typography->features = heap_alloc(typography->allocated*sizeof(DWRITE_FONT_FEATURE)); typography->features = heap_calloc(typography->allocated, sizeof(*typography->features));
if (!typography->features) { if (!typography->features) {
heap_free(typography); heap_free(typography);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;

View File

@ -483,13 +483,14 @@ HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedSt
return S_FALSE; return S_FALSE;
strings = impl_from_IDWriteLocalizedStrings(iface); strings = impl_from_IDWriteLocalizedStrings(iface);
strings_clone = heap_alloc(sizeof(struct localizedstrings)); strings_clone = heap_alloc(sizeof(*strings_clone));
if (!strings_clone) return E_OUTOFMEMORY; if (!strings_clone)
return E_OUTOFMEMORY;
strings_clone->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl; strings_clone->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
strings_clone->ref = 1; strings_clone->ref = 1;
strings_clone->count = strings->count; strings_clone->count = strings->count;
strings_clone->data = heap_alloc(sizeof(struct localizedpair) * strings_clone->count); strings_clone->data = heap_calloc(strings_clone->count, sizeof(*strings_clone->data));
if (!strings_clone->data) { if (!strings_clone->data) {
heap_free(strings_clone); heap_free(strings_clone);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;