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: slice valarrays with std::string -> segfault


Paolo Carlini wrote:

>Gaby, I see __valarray_copy used (instead of __valarray_copy_construct)
>by the conversion constructor from slice_array for any type T: i.e., no
>placement new, that cannot possibly work a T such as 'struct element' in
>the posted snippet. Indeed, lots and lots of errors from valgrind...
>  
>
Just to explain concretely what I mean, the attached quick and dirty
hack avoids the Seg fault and makes valgrind happy. I think it tells us
something...

Paolo.

P.S. Conversation moved to libstdc++.

////////////
Index: bits/valarray_array.h
===================================================================
--- bits/valarray_array.h	(revision 108312)
+++ bits/valarray_array.h	(working copy)
@@ -456,6 +456,11 @@
     __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b)
     { std::__valarray_copy(__a._M_data, __n, __s, __b._M_data); }
 
+  template<typename _Tp>
+    inline void
+    __valarray_construct(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b)
+    { std::__valarray_copy_construct(__a._M_data, __n, __s, __b._M_data); }
+
   // Copy a plain array  __a[<__n>] into a strided array __b[<__n : __s>]
   template<typename _Tp>
     inline void
Index: std/std_valarray.h
===================================================================
--- std/std_valarray.h	(revision 108312)
+++ std/std_valarray.h	(working copy)
@@ -584,7 +584,7 @@
     valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)
     : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
     {
-      std::__valarray_copy
+      std::__valarray_construct
 	(__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
     }
 

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