From 2adb01a47cfec4f9dd902956820d4f9a800b736c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Apr 2026 22:04:57 -0600 Subject: [PATCH] [internal] Replace remaining vector resize(0) with clear() Two callers were still using vector.resize(0) to drop accumulated data: graph/serialize.hh's overflow tracking and hb_bit_set_t's clear() (via its own internal resize()). resize(0) on a vector in error state short-circuits without zeroing length, leaving stale entries that downstream code then walks as if valid. Fix both: - serialize.hh: call overflows->clear() instead. - hb-bit-set.hh: reimplement clear() to zero length/population unconditionally by calling pages.clear() / page_map.clear() directly, bypassing the internal resize() that bails when `successful` is false. Mirrors the March clear() fix in hb-vector.hh (commit d134f88824). Assisted-by: Claude --- src/graph/serialize.hh | 2 +- src/hb-bit-set.hh | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index 37fac8909..4f89f1011 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -108,7 +108,7 @@ inline bool will_overflow (graph_t& graph, hb_vector_t* overflows = nullptr) { - if (overflows) overflows->resize (0); + if (overflows) overflows->clear (); graph.update_positions (); hb_hashmap_t record_set; diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 05725048c..0d612438d 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -117,9 +117,11 @@ struct hb_bit_set_t void clear () { - resize (0); - if (likely (successful)) - population = 0; + /* Always zero length and population, even when in error state, + * so a stale set can't leak pages into a subsequent reuse. */ + pages.clear (); + page_map.clear (); + population = 0; } bool is_empty () const {