Holger Brunn wrote:
cString &cString::operator=(const cString &String) {
- free(s);
- if(s!=String.s)
- {
- free(s);
- } s = String.s ? strdup(String.s) : NULL; return *this;
}
Doesn't this cause a memory leak? It'll strdup() the old string and then lose the old pointer to it. Looks to me like it should instead be:
if(s!=String.s) { free(s); s = String.s ? strdup(String.s) : NULL; }
or maybe something like: if (&String == this) return *this;
Jon