From 6c272b920d14f34494a8415bad15e794be313fc5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jan 2023 13:00:41 -0700 Subject: [PATCH] [set] Don't discard allocation in operator= That had caused memory thrashing. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54789 --- src/hb-bit-set.hh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index a38da130a..e7310e054 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -38,7 +38,7 @@ struct hb_bit_set_t hb_bit_set_t () = default; ~hb_bit_set_t () = default; - hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other); } + hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other, true); } hb_bit_set_t ( hb_bit_set_t&& other) : hb_bit_set_t () { hb_swap (*this, other); } hb_bit_set_t& operator= (const hb_bit_set_t& other) { set (other); return *this; } hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; } @@ -85,10 +85,10 @@ struct hb_bit_set_t void err () { if (successful) successful = false; } /* TODO Remove */ bool in_error () const { return !successful; } - bool resize (unsigned int count, bool clear = true) + bool resize (unsigned int count, bool clear = true, bool exact_size = false) { if (unlikely (!successful)) return false; - if (unlikely (!pages.resize (count, clear, true) || !page_map.resize (count, clear, true))) + if (unlikely (!pages.resize (count, clear, exact_size) || !page_map.resize (count, clear, exact_size))) { pages.resize (page_map.length); successful = false; @@ -346,11 +346,11 @@ struct hb_bit_set_t hb_codepoint_t c = first - 1; return next (&c) && c <= last; } - void set (const hb_bit_set_t &other) + void set (const hb_bit_set_t &other, bool exact_size = false) { if (unlikely (!successful)) return; unsigned int count = other.pages.length; - if (unlikely (!resize (count, false))) + if (unlikely (!resize (count, false, exact_size))) return; population = other.population;