This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: slice valarrays with std::string -> segfault
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: Jhair Tocancipa Triana <jhair_tocancipa at gmx dot net>, libstdc++ <libstdc++ at gcc dot gnu dot org>, Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Sat, 10 Dec 2005 22:27:22 +0100
- Subject: Re: slice valarrays with std::string -> segfault
- References: <87irtx8bcr.fsf@mandala.my-fqdn.de> <439B34F2.4000808@suse.de> <439B3B77.1060807@suse.de>
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));
}