From f08685b0974bda0a3e7b631ce675c234169f1f16 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 11 Jul 2017 09:32:44 +0200 Subject: [PATCH] Fix issue with reserve for array. --- m-array.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/m-array.h b/m-array.h index 306c2e2a..30a8d8ac 100644 --- a/m-array.h +++ b/m-array.h @@ -315,13 +315,19 @@ if (v->size > alloc) { \ alloc = v->size; \ } \ - type *ptr = M_GET_REALLOC oplist (type, v->ptr, alloc); \ - if (M_UNLIKELY (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ - return; \ + if (M_UNLIKELY (alloc == 0)) { \ + M_GET_FREE oplist (v->ptr); \ + v->size = v->alloc = 0; \ + v->ptr = NULL; \ + } else { \ + type *ptr = M_GET_REALLOC oplist (type, v->ptr, alloc); \ + if (M_UNLIKELY (ptr == NULL) ) { \ + M_MEMORY_FULL(sizeof (type) * alloc); \ + return; \ + } \ + v->ptr = ptr; \ + v->alloc = alloc; \ } \ - v->ptr = ptr; \ - v->alloc = alloc; \ ARRAYI_CONTRACT(v); \ } \ \