473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Segmentation fault in copy algorithm

Hi,

I wrote a template to use copy() algorithm, called copyAll:
template<class T>
void copyAll(const T& src , T& dest ) {
copy (src.begin(), src.end(), back_inserter(dest));
}

but when I call it, I get a segmentation fault:
Thread [0] (Suspended: Signal 'SIGSEGV' received. Description:
Segmentation fault.)
21 __gnu_cxx::__mt_alloc_base<BlockData*>::construct( ) at
/usr/include/c++/4.0.2/ext/mt_allocator.h:585 0x0804ab8d
20 std::vector<BlockData*, std::allocator<BlockData*> >::push_back()
at /usr/include/c++/4.0.2/bits/stl_vector.h:606 0x0804b6d0
19 std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > >::operator=() at
/usr/include/c++/4.0.2/bits/stl_iterator.h:364 0x080560b1
18 std::__copy<false,
std::random_access_iterator_tag>::copy<BlockData* const*,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:285 0x080560ef
17 std::__copy_aux<BlockData* const*,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:317 0x08056143
16 std::__copy_normal<true,
false>::copy_n<__gnu_cxx::__normal_iterator<BlockD ata* const*,
std::vector<BlockData*, std::allocator<BlockData*> > >,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:335 0x08056191
15 std::copy<__gnu_cxx::__normal_iterator<BlockData* const*,
std::vector<BlockData*, std::allocator<BlockData*> > >,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:387 0x080561ce
14 copyAll<std::vector<BlockData*, std::allocator<BlockData*> > >() at
.../Utils.h:222 0x080609cc
13 DeviantBlockGrouper::handleKey() at ../DeviantBlockGrouper.cpp:132
0x0807fcc1
12 DeviantBlockGrouper::handlegroup() at ../DeviantBlockGrouper.cpp:66
0x0807fe47
11 BlockGrouper::do_group() at ../BlockGrouper.cpp:35 0x08056237
10 boost::lambda::function_adaptor<void() at
/usr/include/boost/lambda/detail/function_adaptors.hpp:346 0x080576fc
9 boost::lambda::function_action<5,
boost::lambda::detail::unspecified>::apply<void, void() at
/usr/include/boost/lambda/detail/actions.hpp:114 0x08057727
8 boost::lambda::lambda_functor_base<boost::lambda:: action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>
, boost::tuples::tuple<void() at /usr/include/boost/lambda/detail/lambda_functor_base.hpp:461 0x08058369 7
boost::lambda::lambda_functor<boost::lambda::lambd a_functor_base<boost::lambda::action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>, boost::tuples::tuple<void() at /usr/include/boost/lambda/detail/lambda_functors.hpp:148 0x08058398 6 std::for_each<__gnu_cxx::__normal_iterator<Pattern Matcher**,
std::vector<PatternMatcher*, std::allocator<PatternMatcher*> > >,
boost::lambda::lambda_functor<boost::lambda::lambd a_functor_base<boost::lambda::action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>, boost::tuples::tuple<void() at /usr/include/c++/4.0.2/bits/stl_algo.h:158 0x080583c1

Any idea is appreciated.

Mar 5 '06 #1
1 3168
I think I resolve my problem. Sorry for the inconvince.

sa***************@gmail.com wrote:
Hi,

I wrote a template to use copy() algorithm, called copyAll:
template<class T>
void copyAll(const T& src , T& dest ) {
copy (src.begin(), src.end(), back_inserter(dest));
}

but when I call it, I get a segmentation fault:
Thread [0] (Suspended: Signal 'SIGSEGV' received. Description:
Segmentation fault.)
21 __gnu_cxx::__mt_alloc_base<BlockData*>::construct( ) at
/usr/include/c++/4.0.2/ext/mt_allocator.h:585 0x0804ab8d
20 std::vector<BlockData*, std::allocator<BlockData*> >::push_back()
at /usr/include/c++/4.0.2/bits/stl_vector.h:606 0x0804b6d0
19 std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > >::operator=() at
/usr/include/c++/4.0.2/bits/stl_iterator.h:364 0x080560b1
18 std::__copy<false,
std::random_access_iterator_tag>::copy<BlockData* const*,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:285 0x080560ef
17 std::__copy_aux<BlockData* const*,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:317 0x08056143
16 std::__copy_normal<true,
false>::copy_n<__gnu_cxx::__normal_iterator<BlockD ata* const*,
std::vector<BlockData*, std::allocator<BlockData*> > >,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:335 0x08056191
15 std::copy<__gnu_cxx::__normal_iterator<BlockData* const*,
std::vector<BlockData*, std::allocator<BlockData*> > >,
std::back_insert_iterator<std::vector<BlockData*,
std::allocator<BlockData*> > > >() at
/usr/include/c++/4.0.2/bits/stl_algobase.h:387 0x080561ce
14 copyAll<std::vector<BlockData*, std::allocator<BlockData*> > >() at
../Utils.h:222 0x080609cc
13 DeviantBlockGrouper::handleKey() at ../DeviantBlockGrouper.cpp:132
0x0807fcc1
12 DeviantBlockGrouper::handlegroup() at ../DeviantBlockGrouper.cpp:66
0x0807fe47
11 BlockGrouper::do_group() at ../BlockGrouper.cpp:35 0x08056237
10 boost::lambda::function_adaptor<void() at
/usr/include/boost/lambda/detail/function_adaptors.hpp:346 0x080576fc
9 boost::lambda::function_action<5,
boost::lambda::detail::unspecified>::apply<void, void() at
/usr/include/boost/lambda/detail/actions.hpp:114 0x08057727
8 boost::lambda::lambda_functor_base<boost::lambda:: action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>
, boost::tuples::tuple<void() at /usr/include/boost/lambda/detail/lambda_functor_base.hpp:461 0x08058369

7
boost::lambda::lambda_functor<boost::lambda::lambd a_functor_base<boost::lambda::action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>
, boost::tuples::tuple<void() at /usr/include/boost/lambda/detail/lambda_functors.hpp:148 0x08058398

6 std::for_each<__gnu_cxx::__normal_iterator<Pattern Matcher**,
std::vector<PatternMatcher*, std::allocator<PatternMatcher*> > >,
boost::lambda::lambda_functor<boost::lambda::lambd a_functor_base<boost::lambda::action<5,
boost::lambda::function_action<5, boost::lambda::detail::unspecified>
, boost::tuples::tuple<void() at /usr/include/c++/4.0.2/bits/stl_algo.h:158 0x080583c1

Any idea is appreciated.


Mar 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: AMT2K5 | last post by:
Hello guys. I have a function, cleanSpace . I was told from another source that the problem is, is that the function is acting on constant string literal. To fix this I was told to take the...
7
by: silverburgh.meryl | last post by:
Hi, I have a C++ problem which uses STL containers and algorithm and it has a segmentation fault under some condition. Here is a back trace from gdb. Is it possible to tell what is wrong...
1
by: utab | last post by:
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <iterator> using std::cout; using std::vector; using std::string; using std::endl;
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
2
by: tikcireviva | last post by:
Hi Guys, I am not sure what's wrong with my program. When I ran it under the GDB, it shows the following messages , which said that the issue is from stl_list.h. Does anyone know what's...
1
by: jwlkr | last post by:
Hi, I am trying to sort a vector of a user defined type: a class which represents points in cartesian coordinates. The vector of points needs to be sorted according to the value of the...
11
by: John Williams | last post by:
I've written a simple program to do XOR encryption as my first foray into understanding how encryption works. The code compiles fine, however it segmentation faults on every run. using gdb to...
15
by: Rares Vernica | last post by:
Hello, I have a strange problem. I compile my code with g++ (GCC) 4.1.2. My code runs just fine if I use the -O2 optimization flag. valgrind does not report any memory leak. When I use the...
3
by: jr.freester | last post by:
I have created to classes Matrix and System. System is made up of type matrix. ---------------------------------------------------------------------------------- class Matrix { private: int...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.