Combine variable length arrays in C99 and sprintf into new function.
The sprintfa function uses variable length arrays in C99 to create a buffer from c-stack RAM of exactly the right size and perform a sprintf into that buffer. This prevents buffer overflows.
To use this function, declare a character which will be the array name as part of the sprintfa() function:
#include "sprintfa.h"
int main(void) {
char sprintfa(x, "Hello World\n");
puts(x);
return 0;
}
Special thanks to Sam for the details.