473,387 Members | 1,687 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.

please help - seg fault in std::set

Hi,

I am getting a Fatal signal with std::set::insert(). I'm really not
sure what to
try next:

Here is my code:

std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[0] " << t._indices[0] << std::endl;
_indices.insert(t._indices[0]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[1] " << t._indices[1] << std::endl;
_indices.insert(t._indices[1]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[2] " << t._indices[2] << std::endl;
_indices.insert(t._indices[2]);

When I run it I get:
....
max size: 4294967295
size: 56
t._indices[0] 206
max size: 4294967295
size: 56
t._indices[1] 212
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

I changed my code to:
_indices.insert(t._indices[0]);
_indices.insert(t._indices[2]);
_indices.insert(t._indices[1]);

It inserted 2 ok but still failed on 1. Any ideas? How should I go
about
debugging this?

-Jimmy

Jul 23 '05 #1
1 2480
jimmy wrote:
Hi,

I am getting a Fatal signal with std::set::insert(). I'm really not
sure what to
try next:

Here is my code:

std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[0] " << t._indices[0] << std::endl;
_indices.insert(t._indices[0]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[1] " << t._indices[1] << std::endl;
_indices.insert(t._indices[1]);
std::cout << "max size: " << _indices.max_size() << std::endl;
std::cout << "size: " << _indices.size() << std::endl;
std::cout << "t._indices[2] " << t._indices[2] << std::endl;
_indices.insert(t._indices[2]);

When I run it I get:
...
max size: 4294967295
size: 56
t._indices[0] 206
max size: 4294967295
size: 56
t._indices[1] 212
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

I changed my code to:
_indices.insert(t._indices[0]);
_indices.insert(t._indices[2]);
_indices.insert(t._indices[1]);

It inserted 2 ok but still failed on 1. Any ideas? How should I go
about
debugging this?

-Jimmy


We need to see at least the declaration and initialization of "t" and
"_indices" (symbols beginning with an underscore are reserved for the
implementation, btw). A compilable subset of the program would be
preferable.

What happens if you leave out the inserts and just try:
std::cout << t._indices[0] << std::endl;
std::cout << t._indices[2] << std::endl;
std::cout << t._indices[1] << std::endl;

Also, if "t._indices" is a vector, what happens with:
std::cout << t._indices.at(0) << std::endl;
std::cout << t._indices.at(2) << std::endl;
std::cout << t._indices.at(1) << std::endl;

-Alan
Jul 23 '05 #2

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

Similar topics

7
by: ma740988 | last post by:
The position returned via the STL std::set container never made much sense to me. When you insert elements within the container, the position returned - via find - does not reflect the actual...
11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
8
by: gipsy boy | last post by:
I've got a std::set with a custom comparator. When I add things, it puts them in the right place. When I change these objects (and I can tell they are effectively changed), the set doesn't...
10
by: danibe | last post by:
I never had any problems storing pointers in STL containers such std::vector and std::map. The benefit of storing pointers instead of the objects themselves is mainly saving memory resources and...
16
by: Cory Nelson | last post by:
Does anyone know how std::set prevents duplicates using only std::less? I've tried looking through a couple of the STL implementations and their code is pretty unreadable (to allow for different...
2
by: shuisheng | last post by:
Dear All, std::set is sorted. So I am wondering is there any fast way to access (sucn as random access) to its elements just like std::vector. Assume I have a set std::set<inta; So I can...
7
by: desktop | last post by:
In the C++ standard page 472 it says that you can construct a std::set in linear time if the constructor gets a sorted sequence of elements. But how is this possible when insert takes logarithmic...
2
by: mathieu | last post by:
hi there, I would like to know if the following piece of code is garantee to work. I am afraid that the cstring address I am using in the std::map found from a request in std::set is not...
2
by: Markus Dehmann | last post by:
I want to derive from std::set, like shown below. But when I try to declare an iterator over the contained elements I get an error, see the twp uncommented lines: #include <set> template<class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.