> if I type [AFK] the second time the bug log shows
>
> --> bug log: [AFK] - AFK]er)
>       bugf("%s - %s", buf2, buf);
>
>       *p=0;

You aren't putting a null terminator in the string until after you do your
logging.  If you do it before, then you'll get the right output.

As for "cleaning up" memory, C does not initialize memory for you.  You
have to either call a function that does it, like calloc() or do it
yourself with something like memset().

*Generally, if you are using a string function like strdup(), it will add
the null terminator automatically.  However, since you are doing your own
writing to that buffer, you need to add it, and you need to do it prior to
using wrappers for string functions (bugf, in this situation).  It doesn't
matter what gibberish is after the terminator as almost all string
functions trust that the terminator is the end of the string.

*Notwithstanding memory constraints.

Reply via email to