Problem (core dumped) with a list of class "aut_st"

Hi, this is my first topic here, I need help, please.

I have a class autst.c and I declared a list of autst this way:

1
2
3
        list<aut_st> trace;

	aut_st state;


The class autst has the constructor:

1
2
3
4
5
aut_st::aut_st()
	{
		 dimension = 0;
 		info      = NULL;
	}


where info is pointer to int
.
.
.

1
2
3
4
state.create(3); //create a state containing an info with size 3

trace.push_back(state);




The core dumped or glibc detected error occurs when I try to push the state into the trace, I don't know what I have to do to allocate space to each state in each position of the list each time I have to push (if it's the thing I have to do).


Someone can help me, what do I have to do to allocate memory correctly ?

Thanks.
¿Do you have a proper destructor, copy constructor and assignment operator?
I didn't set up a destructor to the list, but the class autst.c has these ones for its objects.
Try to provide a minimal example
I'm doing the follow:

I work with model checking and I have to keep a trace ( e.g., a execution of the system, represented by a set of states). So, each state is a instance of aut_st.

An instance of aut_st has a variable dimension and info ( info is a pointer to int and can be any size).

Then, to keep all the states that belong to the same trace I declared a list of aut_st this way:

list<aut_st> trace;

Before call the method that will mount and keep the trace in the list I do the follow:

1
2
3
4
5
aut_st state;
		state.create(ReachSS.Levels());

trace.push_back(state);


The code above declares a new instance of aut_st and set it up with a size defined by ReachSS.Levels(), for example, 3, then I push the state in the list trace. This first state represents the initial state of my system.

After this first step, I call the method that will keep mounting the trace ( mountTrace() ).

the code below is part of the method

1
2
3
4
5
6
7
8
9
10
11
12
                //here I take the next state of that initial state, that is encoded by ka and pa
                ReachSS.Intersection(ka, pa, kResults.front(), pResults.front(), ka, pa);
		
                //here I set the state encoded by ka and pa in the local variable state
		ReachSS.MTMDD::State(ka, pa, 0, state);
		
		cout << "the state was added" << endl;
		
		//here I push the state in the list
		trace.push_back(state);



The error (core dumped or glibc detected) occurs exatly when I try to push the second state in the list, right after the cout << "the state was added" << endl;

I don't know how to allocate memory to each state of the list before try to push, do you get it ? If it is the right thing to do.

I think that when I declared list<aut_st> trace; I did a list of empty objects aut_st, didn't ?


std::list manages its memory. Every time you do push_back() a node is created and linked, holding a copy of the argument.

I think that the problem is with aut_st. Somewhere you are invalidating the info pointer, so when trying to do the copy the program crash
But it's pretty much a blind guess.

You may want to try std::vector as a resizable array.

Also, make sure that you are not stepping out of bounds.
Hey, thanks a bunch for your attention! =)

I've fixed the problem.

I created a new list of int pointers and I changed the class aut_st in way to return just the info array .

The new list is that:

list< int* > listTrace;

Then I declared a new constructor to aut_st, one which receives two parameters (int v, int * v).

Originally the class aut_st have already a method which returns a pointer to its array info. So each time that I need to keep the state I push into the list the array info. When I need to retrieve the state I just send to new constructor the data from the list.

It works!
Topic archived. No new replies allowed.