STL vector core dump


A

Akila

My application is built on sun solaris 9.0. 5.9 Generic_118558-26
sun4u sparc SUNW,Sun-Fire-V210

compiler : Sun C++ 5.5 Patch 113817-14 2005/07/19

I am creating a vector of int at the beginning of my application
(before the application does anything) and copying it to another
vector . my application segmentation faults!!!

std::vector<int> v1;
std::vector<int> v2 =v1;

The code works fine when the vector v1 is not empty.
std::vector<int> v1;
v1.push_back(10);
std::vector<int> v2 =v1;

Even the below code worked
std::vector<int> v1(1);
std::vector<int> v2 =v1;

I looked at the copy constructor for the vector and it does not seem
to be
checking for zero size.

Can anyone please explain why and also how to solve the problem
becuase i have several functions in my application that return a
vector (when a vector is returned , the copy constructor is called)
and the vector can be empty.

Thanks,
- Akila.
 
Ad

Advertisements

A

anon

Akila said:
My application is built on sun solaris 9.0. 5.9 Generic_118558-26
sun4u sparc SUNW,Sun-Fire-V210

compiler : Sun C++ 5.5 Patch 113817-14 2005/07/19

I am creating a vector of int at the beginning of my application
(before the application does anything) and copying it to another
vector . my application segmentation faults!!!

std::vector<int> v1;
std::vector<int> v2 =v1;

If your example is:
#include <vector>

int main()
{

std::vector<int> v1;
std::vector<int> v2 =v1;
}

then, it works without seg fault with gcc 4.1.2 on Linux machine.
Otherwise, I have no idea what you did

Can anyone please explain why and also how to solve the problem
becuase i have several functions in my application that return a
vector (when a vector is returned , the copy constructor is called)
and the vector can be empty.

Have you tried updating your compiler? Looks like it has some issues
 
J

James Kanze

My application is built on sun solaris 9.0. 5.9 Generic_118558-26
sun4u sparc SUNW,Sun-Fire-V210
compiler : Sun C++ 5.5 Patch 113817-14 2005/07/19
I am creating a vector of int at the beginning of my application
(before the application does anything) and copying it to another
vector . my application segmentation faults!!!
std::vector<int> v1;
std::vector<int> v2 =v1;
The code works fine when the vector v1 is not empty.
std::vector<int> v1;
v1.push_back(10);
std::vector<int> v2 =v1;
Even the below code worked
std::vector<int> v1(1);
std::vector<int> v2 =v1;
I looked at the copy constructor for the vector and it does
not seem to be checking for zero size.
Can anyone please explain why and also how to solve the problem
becuase i have several functions in my application that return a
vector (when a vector is returned , the copy constructor is called)
and the vector can be empty.

There must be something else you're doing wrong. I can't
reproduce the problem, and I tried with all three versions of
Sun CC I have handy: 5.1, 5.5 and 5.8 (both with
-library=stlport4 and without). Could you please post a minimum
example that reproduces the problem.
 
Ad

Advertisements

J

James Kanze

My application is built on sun solaris 9.0. 5.9 Generic_118558-26
sun4u sparc SUNW,Sun-Fire-V210
compiler : Sun C++ 5.5 Patch 113817-14 2005/07/19
I am creating a vector of int at the beginning of my application
(before the application does anything) and copying it to another
vector . my application segmentation faults!!!
std::vector<int> v1;
std::vector<int> v2 =v1;
The code works fine when the vector v1 is not empty.
std::vector<int> v1;
v1.push_back(10);
std::vector<int> v2 =v1;
Even the below code worked
std::vector<int> v1(1);
std::vector<int> v2 =v1;
I looked at the copy constructor for the vector and it does
not seem to be checking for zero size.
Can anyone please explain why and also how to solve the problem
becuase i have several functions in my application that return a
vector (when a vector is returned , the copy constructor is called)
and the vector can be empty.

There must be something else you're doing wrong. I can't
reproduce the problem, and I tried with all three versions of
Sun CC I have handy: 5.1, 5.5 and 5.8 (both with
-library=stlport4 and without). Could you please post a minimum
example that reproduces the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top