Oh yeah, you're right.
Another thing I've done that will work if you have a lot of strcat(), is make a string struct:
ktString {
int len;
int memlen;
char *str;
}
It keeps track of the string's actual length, and the size of the underlying buffer. Then you can 'override' the various string functions:
bool ktStrcat(ktString s1, ktString s2);
bool ktSprintf(ktString s1, ...);
These functions will take care of buffer-size checking, and reallocation if necessary. For cases where you need to interface with pre-existing libraries, you can return a cstring(). Make it a function/macro to enable you to change the struct definition in the future:
#define ktCstr(x) (x)->str
then you can pass it into write() or whatever you need:
write(sock, ktCstr(s), s->len);
Another thing I've done that will work if you have a lot of strcat(), is make a string struct:
It keeps track of the string's actual length, and the size of the underlying buffer. Then you can 'override' the various string functions: These functions will take care of buffer-size checking, and reallocation if necessary. For cases where you need to interface with pre-existing libraries, you can return a cstring(). Make it a function/macro to enable you to change the struct definition in the future: then you can pass it into write() or whatever you need: