hi there
I was wondering if someone could help me.
I'm writing a programme, where I have to return some char array or string.
The problem is, it works only for the first time.. see
Code:
class CliLogic{
private:
char orient, state, * name;
std::string m_buf;
public:
CliLogic(){state = 0; m_buf.reserve(1024);}
void CM( const char * mes);
};
Name receives a pointer from another class, so it should be valid (and actually IS valid, tested..). But take next method CM
Code:
void CliLogic::CM(const char * mes){
printf("Start\n");
m_buf = ""
m_buf.append(name);
printf(".");
m_buf.append(mes);
printf(".");
m_buf.append("\r\n");
printf(".");
printf("%s\n",m_buf.c_str());
}
On the first run it goes like "Start\n...Name message\r\nStart\n segmentation fault". Valgrind says it touches memory on 0x0, but I didn't figure out the fault. The size of the string (or char array, tested on both) shouldn't be a problem. Name is not bigger than 512 bits and message isn't longer than 5 chars + "\r\n".
I have tried it with append and with strcpy (which was originally there), both resulting in segfaults.