You can delete pointers to NULL so
instead of
Code:
if(str != NULL)
delete[] str; // str is of type char*
do this
cString might be invalid but I can't be too sure.
That would throw of new for sure you might
want to throw in a assert statement such as
Code:
assert(len >= 0 && len < 100);
I hope you know how to use gdb because this
bug might require it.
Code:
str = new char[len];
str is global are you sure you release it, it might be
easier to manage the memory if you do something like this
Code:
char* upstring(char* s)
{
char* p = NULL;
if (s != NULL) {
int n = strlen(s);
p = new [n + 1];
strcpy(p, s);
}
return p;
}
Then the class or function that owns str can handle
it locally. Another way could be just to use c++'s string's class