Original Post
I''m currently using a variable arguments function and vsprintf() to parse text to be added to a buffer. My function looks like this:
AddBuffer(const char *entry, ...)
{
...
// parse the arguments list
char parsed_text[2048];
va_list ap;
va_start(ap, entry);
vsprintf(parsed_text, entry, ap);
va_end(ap);
...
}
This works, but it''s not safe. If the parsed string (format + all variables inserted) happens to be longer than the buffer i declared (in this case 2048), this function would crash. I can ''try'' to prevent this by declaring a huge buffer but it''s not very efficient. Anyone knows how i could allocate the buffer depending on the length of the parsed text? The only solution i found is to vfprintf() the text to a FILE and then read the text back from the file into memory (the file will never overflow). But this is not efficient either.
Thanks!
zedd