[wasm-buffer] Fix buffer_contents_realloc
This commit is contained in:
parent
b9d4758bf9
commit
196c6b6c1f
|
@ -50,25 +50,29 @@ HB_WASM_API (bool_t, buffer_contents_realloc) (HB_WASM_EXEC_ENV
|
||||||
if (hb_unsigned_mul_overflows (size, sizeof (glyph_info_t), &bytes))
|
if (hb_unsigned_mul_overflows (size, sizeof (glyph_info_t), &bytes))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO bounds check?
|
glyph_info_t *info = HB_ARRAY_APP2NATIVE (glyph_info_t, contents->info, contents->length);
|
||||||
uint32_t infoptr = contents->info;
|
glyph_position_t *pos = HB_ARRAY_APP2NATIVE (glyph_position_t, contents->pos, contents->length);
|
||||||
uint32_t posptr = contents->pos;
|
|
||||||
|
|
||||||
const char *info = (const char *) addr_app_to_native (infoptr);
|
if (unlikely (!info || !pos))
|
||||||
const char *pos = (const char *) addr_app_to_native (posptr);
|
return false;
|
||||||
|
|
||||||
uint32_t new_info = wasm_runtime_module_dup_data (module_inst, info, bytes);
|
glyph_info_t *new_info = nullptr;
|
||||||
uint32_t new_pos = wasm_runtime_module_dup_data (module_inst, pos, bytes);
|
uint32_t new_inforef = module_malloc (bytes, (void **) &new_info);
|
||||||
|
glyph_position_t *new_pos = nullptr;
|
||||||
|
uint32_t new_posref = module_malloc (bytes, (void **) &new_pos);
|
||||||
|
|
||||||
if (likely (new_info))
|
unsigned old_bytes = contents->length * sizeof (glyph_info_t);
|
||||||
|
if (likely (new_inforef))
|
||||||
{
|
{
|
||||||
contents->info = new_info;
|
memcpy (new_info, info, old_bytes);
|
||||||
module_free (infoptr);
|
module_free (contents->info);
|
||||||
|
contents->info = new_inforef;
|
||||||
}
|
}
|
||||||
if (likely (new_pos))
|
if (likely (new_posref))
|
||||||
{
|
{
|
||||||
contents->pos = new_pos;
|
memcpy (new_pos, pos, old_bytes);
|
||||||
module_free (posptr);
|
module_free (contents->pos);
|
||||||
|
contents->pos = new_posref;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (likely (new_info && new_pos))
|
if (likely (new_info && new_pos))
|
||||||
|
|
Loading…
Reference in New Issue