From a1db4ad4a44c45644d4b4dd6dea701233f01d422 Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Wed, 11 Sep 2002 10:29:28 +0000 Subject: [PATCH] Fixed bug in Grow function (possibly not allocating enough memory if starting with empty array). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@17128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dynarray.cpp | 9 ++++++--- src/common/string.cpp | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/dynarray.cpp b/src/common/dynarray.cpp index 25a7b4a31d..1b3a0353b9 100644 --- a/src/common/dynarray.cpp +++ b/src/common/dynarray.cpp @@ -112,11 +112,14 @@ void name::Grow(size_t nIncrement) \ /* only do it if no more place */ \ if( m_nCount == m_nSize ) { \ if( m_nSize == 0 ) { \ - /* was empty, alloc some memory */ \ - m_pItems = new T[WX_ARRAY_DEFAULT_INITIAL_SIZE]; \ + /* was empty, determine initial size */ \ + size_t size = WX_ARRAY_DEFAULT_INITIAL_SIZE; \ + if (size < nIncrement) size = nIncrement; \ + /* allocate some memory */ \ + m_pItems = new T[size]; \ /* only grow if allocation succeeded */ \ if ( m_pItems ) { \ - m_nSize = WX_ARRAY_DEFAULT_INITIAL_SIZE; \ + m_nSize = size; \ } \ } \ else \ diff --git a/src/common/string.cpp b/src/common/string.cpp index e2563e5c82..32a0adab79 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1762,6 +1762,8 @@ void wxArrayString::Grow(size_t nIncrement) if ( m_nSize == 0 ) { // was empty, alloc some memory m_nSize = ARRAY_DEFAULT_INITIAL_SIZE; + if (m_nSize < nIncrement) + m_nSize = nIncrement; m_pItems = new wxChar *[m_nSize]; } else { -- 2.45.2