Skip to content

Commit 7a098cf

Browse files
committed
fixup??? vreportf(): avoid relying on stdio buffering
In Git for Windows, we merged a newer iteration of that patch. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cb65e00 commit 7a098cf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

usage.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
void vreportf(const char *prefix, const char *err, va_list params)
1010
{
1111
char msg[4096];
12-
size_t off = strlcpy(msg, prefix, sizeof(msg));
1312
char *p, *pend = msg + sizeof(msg);
13+
size_t prefix_len = strlen(prefix);
1414

15-
p = off < pend - msg ? msg + off : pend - 1;
15+
if (sizeof(msg) <= prefix_len) {
16+
fprintf(stderr, "BUG!!! too long a prefix '%s'\n", prefix);
17+
abort();
18+
}
19+
memcpy(msg, prefix, prefix_len);
20+
p = msg + prefix_len;
1621
if (vsnprintf(p, pend - p, err, params) < 0)
1722
*p = '\0'; /* vsnprintf() failed, clip at prefix */
1823

0 commit comments

Comments
 (0)