]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixed bug in Grow function (possibly not allocating enough memory if starting
authorStefan Neis <Stefan.Neis@t-online.de>
Wed, 11 Sep 2002 10:29:28 +0000 (10:29 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Wed, 11 Sep 2002 10:29:28 +0000 (10:29 +0000)
        with empty array).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@17128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/dynarray.cpp
src/common/string.cpp

index 25a7b4a31d0d868f45b3aa2d98e342733c21644d..1b3a0353b9703e132cbc220cec62dc3f992537c6 100644 (file)
@@ -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                                                                    \
index e2563e5c824bc1bfc8e07aafc5443a0fbb827964..32a0adab794701d9f9fbd456e5f9e415e85a60b7 100644 (file)
@@ -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 {