2 ms·
"fmt2" is supposed to contain a format string. It's supposed to contain the format string from "fmt". That's how it prints the args from "ap". The bug is when
by Karellen 15y ago
"fmt2" is supposed to contain a format string. It's supposed to contain the format string from "fmt". That's how it prints the args from "ap".
The bug is when getprogname() also returns a string containing a format specifier (e.g. "%s"), which is not expected.
Clearly the fix is:
fprintf(stderr, "%s: ", getprogname());
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
(Edit for formatting, clarity)