I implemented an easy list structure where single list elements are defined by the following structure:
struct list_elem {
struct list_elem *next; // ptr to the next element
char *data; // ptr to data
};
Now, I want to do the following:
struct list_elem *elem;
int main() {
elem->data = "some_string";
strcat(elem->data, "another_string");
}
I am worried about an overrun because the man page of strcat states:
The
char *strcat(char *dest, const char *src)
function appends thesrc
string to thedest
string, overwriting the terminating null byte ('\0') at the end ofdest
, and then adds a terminating null byte. The strings may not overlap, and thedest
string must have enough space for the result. Ifdest
is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs.
And basically I got no idea how much memory is allocated for my list element.