Error: Run-Time Check failure #2 stack around the variable x was corrupted...(Urgently please)

Dear i need your help very urgently.
Before this program was running without any error but now it is giving this error
Error: Run-Time Check failure #2 stack around the variable "all_variables" was corrupted


Here is the code, i try to debug, it gives this error at the end of this function when it return value.
Even i try at another machine but the error was same. I am using VS2008
Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
SubSets MMPCbar::computeSubSets(std::vector<int> CpcList)
{
    //! To calculate all subsets
	//! First create plVariablesConjunction of all variables
	//! then by using plValues object, iterate all possible combinations 
	//! of the form 01011. corresponding to 1 store variable index in the combination list
	//! at the end put all these combinations in another list.
	
	SubSets subSetsCPC;
	vector< int > combinations;
	plVariablesConjunction all_variables;


	// if Cpc list is empty then return empty set
	if (CpcList.size()==0)
	{
		subSetsCPC.push_back(CpcList);
		return subSetsCPC;
	}
	
	// If list not empty then calculate subsets
	for (int i = 0; i < CpcList.size(); i++)
	{
		//cout<<" "<< CpcList[i];
		std::ostringstream symbol_name;  
		symbol_name << CpcList.at(i);
		plSymbol symbol(symbol_name.str(), plIntegerType(0,1));
		all_variables = all_variables ^ symbol;
	}
	plValues vals(all_variables);
	vals.reset();

	do {
		//cout<<"\n";

		for (unsigned int j = 0; j < CpcList.size(); j++)
		{
			if(vals[j] == 1) // combination will be in the form of 011011, corresponding to 1 add variable in the combination.
			{
				//cout<<" "<< CpcList[j];
				combinations.push_back(CpcList.at(j));
			}
		}
		subSetsCPC.push_back(combinations);
		combinations.clear(); // reset list
	}while (vals.next());

return subSetsCPC;
}
You need to post the definitions for:
- plVariablesConjunction
- plIntegerType
- plValues
- SubSets
typedef std::vector< vector <int> > SubSets;

But others are the classes of the ProBT library.
class PL_DLL_API plVariablesConjunction : public plSampleSpaceObject
class PL_DLL_API plValues : public plSampleSpaceObject
class PL_DLL_API plIntegerType: public plDiscreteType
Without seeing the definition of plSymbol, I can't tell what's happening here:
 
plSymbol symbol(symbol_name.str(), plIntegerType(0,1));
.str() returns a temp, so should pass it by value.


Without seeing the definition of plVariablesConjunction, I can't tell what's happening here:
 
all_variables = all_variables ^ symbol;



Without seeing the definition of plValues, I can't tell what's happening here:
1
2
plValues vals(all_variables);
vals.reset();
or here:
 
if(vals[j] == 1)
or here:
 
vals.next()


Is subSetsCPC an empty set if it has an empty collection in it? Isn't it a set that contains an empty set?
Yes, but as these are 3rd party library so, it is difficult to explain.

But yes, when this function generate this error, the subSetsCPC set is empty. For this call function should reply an empty set.
If you have the source, you can step thru the code in a debugger to check that the code's doing what you expect.
In VS2005, In Debugger > Exceptions, you can enable breakpoints for each type of exception. If you have that in VS2008, try enabling all exception breakpoints and see if it stops earlier to give you a clue

Last time i had this kind of error, I had different struct member alignment in 2 libs of a project, so a structure had not the same time in one or the other, causing memory overflows
Topic archived. No new replies allowed.