From: Junio C Hamano Date: Mon, 02 May 2016 18:26:02 GMT Subject: Re: [PATCH 01/41] usage.c: move format processing out of die_errno() Message-ID: In-Reply-To: Eric Sunshine writes: > On Sun, May 1, 2016 at 7:14 AM, Nguyễn Thái Ngọc Duy wrote: >> fmt_with_err() will be shared with the coming error_errno() and >> warning_errno(). >> >> Signed-off-by: Nguyễn Thái Ngọc Duy >> --- >> diff --git a/usage.c b/usage.c >> @@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...) >> -void NORETURN die_errno(const char *fmt, ...) >> +static const char *fmt_with_err(const char *fmt) >> { >> - va_list params; >> - char fmt_with_err[1024]; >> + static char fmt_with_err[1024]; > > Rather than this static buffer, did you consider having the caller > pass in the buffer? > > static const char *fmt_with_err(char *buf, size_t n, const char *fmt) > { > ... > snprintf(buf, n, "%s: %s", fmt, str_error); > return buf; > } > > void die_errno(const char *fmt, ...) > { > char fmtbuf[1024]; > ... > die_routine(fmt_with_err(fmtbuf, sizeof(fmtbuf), fmt), > params); > ... > } > > Better? Worse? Indifferent? Caller supplied buffer would be the way to go when multiple threads could be showing errors and warnings, right? It would not make too much of a difference for die(), though.