From 43ce6e74d1f3b4400060be95efb642bafabfac1e Mon Sep 17 00:00:00 2001 From: BillionClaw <267901332+BillionClaw@users.noreply.github.com> Date: Tue, 17 Mar 2026 16:47:33 +0800 Subject: [PATCH] fix(container): add empty check to Heap::pop() to prevent UB Calling pop() on an empty heap caused undefined behavior by invoking pop_back() on an empty container. Add an early return to safely handle this edge case. Fixes potential undefined behavior in zvec_pop operations. --- src/include/zvec/ailego/container/heap.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/zvec/ailego/container/heap.h b/src/include/zvec/ailego/container/heap.h index fce03674..33f4cb41 100644 --- a/src/include/zvec/ailego/container/heap.h +++ b/src/include/zvec/ailego/container/heap.h @@ -91,6 +91,9 @@ class Heap : public TBase { //! Pop the front element void pop(void) { + if (TBase::empty()) { + return; + } if (TBase::size() > 1) { auto last = TBase::end() - 1; this->replace_heap(TBase::begin(), last, std::move(*last));