What's going wrong with this snippet:
int trace_printf(const char* filespec, int line, const char* format...)
{
char format_buffer[1024]; // it looks silly, but consider it OK for now
sprintf(format_buffer, "%s(%d) : %s", filespec, line, format);
va_list arg_list = NULL;
va_start(arg_list, format);
int n = printf(format_buffer, arg_list);
va_end(arg_list);
return n;
}
Test:
When calling: trace_printf("Filename", 0, "Everything's %s.", "OK");, I expect output: "Filename(0) : Everything's OK.", instead it may print "Filename(0) : Everything's F\÷." or some other garbish text at the end. I know printf familly are decades old deeply tested functions. I'm sure I'm missing something in between. There are some workarounds, ofcourse, but my intrest is WHY this particular snippet does fail? Can you help me to find it out?
For more information I use MS Visual studio 16.