Maybe you can use snprintf() to avoid buffer overflows