Boost logo

Boost-Commit :

From: droba_at_[hidden]
Date: 2008-08-18 14:32:52


Author: pavol_droba
Date: 2008-08-18 14:32:51 EDT (Mon, 18 Aug 2008)
New Revision: 48198
URL: http://svn.boost.org/trac/boost/changeset/48198

Log:
fox for allocation bug in is_any_ofF

Text files modified:
   trunk/boost/algorithm/string/detail/classification.hpp | 48 +++++++++++++++++++++++++---------------
   1 files changed, 30 insertions(+), 18 deletions(-)

Modified: trunk/boost/algorithm/string/detail/classification.hpp
==============================================================================
--- trunk/boost/algorithm/string/detail/classification.hpp (original)
+++ trunk/boost/algorithm/string/detail/classification.hpp 2008-08-18 14:32:51 EDT (Mon, 18 Aug 2008)
@@ -28,11 +28,7 @@
 
 // classification functors -----------------------------------------------//
 
-#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
-#pragma warning(push)
-#pragma warning(disable:4512) //assignment operator could not be generated
-#endif
- // is_classified functor
+ // is_classified functor
             struct is_classifiedF :
                 public predicate_facade<is_classifiedF>
             {
@@ -42,7 +38,6 @@
                 // Constructor from a locale
                 is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
                     m_Type(Type), m_Locale(Loc) {}
-
                 // Operation
                 template<typename CharT>
                 bool operator()( CharT Ch ) const
@@ -59,13 +54,10 @@
                 #endif
 
             private:
- const std::ctype_base::mask m_Type;
- const std::locale m_Locale;
+ std::ctype_base::mask m_Type;
+ std::locale m_Locale;
             };
 
-#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
-#pragma warning(pop)
-#endif
 
             // is_any_of functor
             /*
@@ -144,31 +136,51 @@
                 {
                     if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0)
                     {
- delete m_Storage.m_dynSet;
+ delete [] m_Storage.m_dynSet;
                     }
                 }
 
                 // Assignment
                 is_any_ofF& operator=(const is_any_ofF& Other)
                 {
- // Prepare storage
- m_Storage.m_dynSet=0;
- m_Size=Other.m_Size;
+ // Prepare storage
                     const set_value_type* SrcStorage=0;
                     set_value_type* DestStorage=0;
 
- if(m_Size<=FIXED_STORAGE_SIZE)
+ if(Other.m_Size<=FIXED_STORAGE_SIZE)
                     {
                         // Use fixed storage
                         DestStorage=&m_Storage.m_fixSet[0];
                         SrcStorage=&Other.m_Storage.m_fixSet[0];
+
+ // Delete old storage if was present
+ if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0)
+ {
+ delete [] m_Storage.m_dynSet;
+ }
+
+ // Set new size
+ m_Size=Other.m_Size;
                     }
                     else
                     {
                         // Use dynamic storage
- m_Storage.m_dynSet=new set_value_type[m_Size];
- DestStorage=m_Storage.m_dynSet;
+
+ // Create new buffer
+ set_value_type* pTemp=new set_value_type[Other.m_Size];
+ DestStorage=pTemp;
                         SrcStorage=Other.m_Storage.m_dynSet;
+
+ // Delete old storage if necessary
+ if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0)
+ {
+ delete [] m_Storage.m_dynSet;
+ }
+
+ // Store the new storage
+ m_Storage.m_dynSet=pTemp;
+ // Set new size
+ m_Size=Other.m_Size;
                     }
 
                     // Use fixed storage


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk