From 53b087f045ebd5aa4ddca2b44b896ca61ba52e1a Mon Sep 17 00:00:00 2001 From: Valery Mironov <32071355+MBkkt@users.noreply.github.com> Date: Wed, 23 Nov 2022 01:30:50 +0300 Subject: [PATCH 1/2] Update compact_array.h --- src/s2/util/gtl/compact_array.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/s2/util/gtl/compact_array.h b/src/s2/util/gtl/compact_array.h index cbc4fe9a..9de05c61 100644 --- a/src/s2/util/gtl/compact_array.h +++ b/src/s2/util/gtl/compact_array.h @@ -413,7 +413,9 @@ class compact_array_base { value_allocator_type allocator; T* new_ptr = allocator.allocate(capacity()); - memcpy(new_ptr, Array(), old_capacity * sizeof(T)); + if (old_capacity != 0) { + memcpy(new_ptr, Array(), old_capacity * sizeof(T)); + } allocator.deallocate(Array(), old_capacity); SetArray(new_ptr); From 2eced6ba04d291503a473e611e5bba6a0e64180f Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Mon, 28 Nov 2022 08:31:48 +0100 Subject: [PATCH 2/2] compact_array: Do no deallocate if old_capacity is 0 Co-authored-by: Valery Mironov <32071355+MBkkt@users.noreply.github.com> --- src/s2/util/gtl/compact_array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s2/util/gtl/compact_array.h b/src/s2/util/gtl/compact_array.h index 9de05c61..033db144 100644 --- a/src/s2/util/gtl/compact_array.h +++ b/src/s2/util/gtl/compact_array.h @@ -415,8 +415,8 @@ class compact_array_base { T* new_ptr = allocator.allocate(capacity()); if (old_capacity != 0) { memcpy(new_ptr, Array(), old_capacity * sizeof(T)); + allocator.deallocate(Array(), old_capacity); } - allocator.deallocate(Array(), old_capacity); SetArray(new_ptr); }