From c3646b65ad6fd41efb5235bcb4e489f2668a71e8 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 24 Jan 2025 20:54:45 +0800 Subject: [PATCH] fix `c11_vector__extend` --- include/pocketpy/common/vector.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/pocketpy/common/vector.h b/include/pocketpy/common/vector.h index a37ae111..93f784f4 100644 --- a/include/pocketpy/common/vector.h +++ b/include/pocketpy/common/vector.h @@ -41,7 +41,9 @@ void c11_vector__swap(c11_vector* self, c11_vector* other); #define c11_vector__extend(T, self, p, size) \ do { \ - c11_vector__reserve((self), (self)->length + (size)); \ + int min_capacity = (self)->length + (size); \ + if((self)->capacity < min_capacity) \ + c11_vector__reserve((self), c11__max((self)->capacity * 2, min_capacity)); \ memcpy((T*)(self)->data + (self)->length, (p), (size) * sizeof(T)); \ (self)->length += (size); \ } while(0)