find.cpp
Code:
void find(vector<macros> &m, file &f)
{
char *c_file;
c_file=new char[f.oldLength()];
f.oldFile().copy(c_file, f.oldLength());
for(int x=0;x<f.oldLength();x++)
{
if(c_file[x]=='#')
{
x++;
if(isValidMacro(c_file,x))
{
x+=5;
f.addMacro();
m.push_back(macros());
m[f.numOfMacros()].atLoc(x);
m[f.numOfMacros()].toSymbol(getSymbol(c_file,x));
}
}
}
}
string getSymbol(char *c_file, int &pos)
{
stringstream ss_symbol;
string symbol;
do
{
pos++;
}while(c_file[pos]!=' ');
do
{
ss_symbol<<c_file[pos];
pos++;
}while(c_file[pos]!='('&&c_file[pos]!=' ');
ss_symbol>>symbol;
return symbol;
}
macros.cpp (implementation file for the macros class, this function causes the crash)
Code:
void macros::toSymbol(string newSymbol)
{
pSymbol=newSymbol;
}
macros.h (class declaration)
Code:
class macros
{
public:
macros();
~macros();
void toSymbol(string newSymbol), toToken(string newToken), atLoc(int location);
string symbol(), token(), args(int num);
int numOfArgs(), loc();
private:
string pSymbol, pToken, *pArgs;
int pNumOfArgs, pLocation;
};
Starting with the find() function, everything appears to work fine. The Code::Blocks debugger stopped working for me and I'm not quite as good at using gdb manually.. But I can tell it's the line pSymbol=newSymbol; that's causing the crash. I did some checking and similar functions in the macro class cause a crash during variable assignment. I have no idea what this is about.
Thanks.