This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::vector: Memory allocation in copy constructor for empty vector


Paolo Carlini wrote:

I think we should do 2), seems doable. I'm looking into it.

To wit, I'm testing this kind of change. Seems safe. You should be able to apply it essentially unchanged to your 4.1 tree and give it a try.


Paolo.

/////////////
Index: stl_vector.h
===================================================================
--- stl_vector.h	(revision 127610)
+++ stl_vector.h	(working copy)
@@ -125,12 +125,12 @@
 
       _Tp*
       _M_allocate(size_t __n)
-      { return _M_impl.allocate(__n); }
+      { return __n != 0 ? _M_impl.allocate(__n) : 0; }
 
       void
       _M_deallocate(_Tp* __p, size_t __n)
       {
-	if (__p)
+	if (__p && __n)
 	  _M_impl.deallocate(__p, __n);
       }
     };

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]