Skip to content

Commit b5a9e43

Browse files
peffgitster
authored andcommitted
Revert "vreportf: avoid intermediate buffer"
This reverts commit f4c3edc. The purpose of that commit was to let us write errors of arbitrary length to stderr by skipping the intermediate buffer and sending our varargs straight to fprintf. That works, but it comes with a downside: we do not get access to the varargs before they are sent to stderr. On balance, it's not a good tradeoff. Error messages larger than our 4K buffer are quite uncommon, and we've lost the ability to make any modifications to the output (e.g., to remove non-printable characters). The only way to have both would be one of: 1. Write into a dynamic buffer. But this is a bad idea for a low-level function that may be called when malloc() has failed. 2. Do our own printf-format varargs parsing. This is too complex to be worth the trouble. Let's just revert that change and go back to a fixed buffer. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit b5a9e43

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

usage.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77
#include "cache.h"
88

99
static FILE *error_handle;
10-
static int tweaked_error_buffering;
1110

1211
void vreportf(const char *prefix, const char *err, va_list params)
1312
{
13+
char msg[4096];
1414
FILE *fh = error_handle ? error_handle : stderr;
15-
16-
fflush(fh);
17-
if (!tweaked_error_buffering) {
18-
setvbuf(fh, NULL, _IOLBF, 0);
19-
tweaked_error_buffering = 1;
20-
}
21-
22-
fputs(prefix, fh);
23-
vfprintf(fh, err, params);
24-
fputc('\n', fh);
15+
vsnprintf(msg, sizeof(msg), err, params);
16+
fprintf(fh, "%s%s\n", prefix, msg);
2517
}
2618

2719
static NORETURN void usage_builtin(const char *err, va_list params)
@@ -78,7 +70,6 @@ void set_die_is_recursing_routine(int (*routine)(void))
7870
void set_error_handle(FILE *fh)
7971
{
8072
error_handle = fh;
81-
tweaked_error_buffering = 0;
8273
}
8374

8475
void NORETURN usagef(const char *err, ...)

0 commit comments

Comments
 (0)