diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index d12a582d0..c55c272f0 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -320,16 +320,17 @@ struct tuple_delta_t return *this; } - void copy_from (const tuple_delta_t& o, hb_alloc_pool_t *pool = nullptr) + bool copy_from (const tuple_delta_t& o, hb_alloc_pool_t *pool = nullptr) { axis_tuples = o.axis_tuples; - indices.duplicate_vector_from_pool (pool, o.indices); - deltas_x.duplicate_vector_from_pool (pool, o.deltas_x); - deltas_y.duplicate_vector_from_pool (pool, o.deltas_y); - compiled_tuple_header.duplicate_vector_from_pool (pool, o.compiled_tuple_header); - compiled_deltas.duplicate_vector_from_pool (pool, o.compiled_deltas); - compiled_peak_coords.duplicate_vector_from_pool (pool, o.compiled_peak_coords); - compiled_interm_coords.duplicate_vector_from_pool (pool, o.compiled_interm_coords); + return !axis_tuples.in_error () && + indices.duplicate_vector_from_pool (pool, o.indices) && + deltas_x.duplicate_vector_from_pool (pool, o.deltas_x) && + deltas_y.duplicate_vector_from_pool (pool, o.deltas_y) && + compiled_tuple_header.duplicate_vector_from_pool (pool, o.compiled_tuple_header) && + compiled_deltas.duplicate_vector_from_pool (pool, o.compiled_deltas) && + compiled_peak_coords.duplicate_vector_from_pool (pool, o.compiled_peak_coords) && + compiled_interm_coords.duplicate_vector_from_pool (pool, o.compiled_interm_coords); } void remove_axis (hb_tag_t axis_tag) @@ -427,7 +428,13 @@ struct tuple_delta_t tuple_delta_t new_var; if (i < solutions.length - 1) - new_var.copy_from (*this, pool); + { + if (unlikely (!new_var.copy_from (*this, pool))) + { + out.ensure_error (); + return; + } + } else new_var = std::move (*this); @@ -1158,6 +1165,7 @@ struct TupleVariationData { // This may move var out. var.change_tuple_var_axis_limit (axis_tag, *axis_limit, axis_triple_distances, out, scratch, pool); + if (unlikely (out.in_error ())) return false; if (!out) continue; unsigned new_len = new_vars.length + out.length; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 36ca91e7f..58a758a9e 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -638,7 +638,8 @@ struct hb_vector_t { assert (!length && !allocated); arrayZ = (Type *) allocator->alloc (size * sizeof (Type), alignof (Type)); - if (unlikely (!arrayZ)) + /* The pool returns nullptr for a zero-size request; that is not a failure. */ + if (unlikely (size && !arrayZ)) { set_error (); return false; diff --git a/src/test-vector.cc b/src/test-vector.cc index b81392058..97195b749 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -27,6 +27,7 @@ #include "hb.hh" #include "hb-vector.hh" +#include "hb-alloc-pool.hh" #include "hb-set.hh" #include "hb-map.hh" #include @@ -314,5 +315,18 @@ main (int argc, char **argv) v.push (m); } + /* An empty allocation from a pool with no open chunk is not a failure. */ + { + hb_alloc_pool_t pool; + hb_vector_t v, empty; + hb_always_assert (v.allocate_from_pool (&pool, 0)); + hb_always_assert (!v.in_error ()); + hb_always_assert (v.duplicate_vector_from_pool (&pool, empty)); + hb_always_assert (!v.in_error ()); + hb_always_assert (v.allocate_from_pool (&pool, 2)); + hb_always_assert (!v.in_error ()); + hb_always_assert (v.length == 2); + } + return 0; }