@Jose
The problem with what you're doing is that you basically end up duplicating sprintf functionality.
This is how I'd do it:
a) Use RawDoFmt twice. First time just count the total size of the string. Allocate buffer, RawDoFmt again, now poking chars to the buffer.
or
b) Use RawDoFmt with dynamically expanding buffer putchproc. You'll prolly end up with slightly larger buffer than necessary, but there will be just one RawDoFmt call.