sprintf: do not use alloca

This commit replaces alloca in sprintf by a simple heap allocator. This
fixes a stack corruption bug which occurs when using certain compilers
(e.g. msvc). The problem occurs when alloca and longjmp are used from
within the same frame.
sprintf: do not pre-allocate space for temporary buffer allocation